码迷,mamicode.com
首页 > 移动开发 > 详细

android 通知(android 8.0可用)

时间:2018-05-18 19:26:11      阅读:298      评论:0      收藏:0      [点我收藏+]

标签:create   imp   and   int   系统   bsp   lse   oid   code   

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可用)

标签:create   imp   and   int   系统   bsp   lse   oid   code   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!