首页 > 移动平台 > 详细

android 通知(android 8.0可用)

时间:2018-05-18 19:18:25      阅读:176      评论:0      收藏:0      [点我收藏+]
final String CHANNEL_ID = "channel_id_1";
final String CHANNEL_NAME = "channel_name_1";

NotificationManager mManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
Notification.Builder builder = null;


if(Build.VERSION.SDK_INT < Build.VERSION_CODES.O){
        builder = new Notification.Builder(this);
}else{
        NotificationChannel notificationChannel = new NotificationChannel(Config.CHANNEL_ID,
                    Config.CHANNEL_NAME, NotificationManager.IMPORTANCE_HIGH);
            //如果这里用IMPORTANCE_NOENE就需要在系统的设置里面开启渠道,
            //通知才能正常弹出
            
    mManager.createNotificationChannel(notificationChannel);
            builder = new Notification.Builder(this,Config.CHANNEL_ID);
}

notification = builder.build();
mManager.notify(555, notification);

 

android 通知(android 8.0可用)

原文:https://www.cnblogs.com/rchao/p/9057473.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!