美文网首页我爱编程Android学习
解决在Android 8.0无法显示通知

解决在Android 8.0无法显示通知

作者: itkluo88 | 来源:发表于2018-05-25 16:06 被阅读1272次

上次简单总结了显示通知姿势, 但留下了在华为p10, Andrid8.0无法显示通知

https://www.jianshu.com/p/47757ac52f38

今儿,由于要发版, 终于逼出了大招(吹吹水又不犯法)

直接上代码吧, 代码是最好的老师:

String channelId =null;

if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {

channelId ="1";

   NotificationChannel channel =new NotificationChannel(channelId,

            "Channel1", NotificationManager.IMPORTANCE_DEFAULT);

    channel.enableLights(true); //是否在桌面icon右上角展示小红点

    channel.setLightColor(Color.RED); //小红点颜色

    channel.setShowBadge(true); //是否在久按桌面图标时显示此渠道的通知

    notificationManager.createNotificationChannel(channel);

}

NotificationCompat.Builder build =new NotificationCompat.Builder(context, channelId);

判断如过为Android O, 则传入自定义的通知渠道,  否则传null。 

over, has fun!

参考: Android O(8.0)通知栏适配 https://blog.csdn.net/rentee/article/details/78303532

相关文章

网友评论

    本文标题:解决在Android 8.0无法显示通知

    本文链接:https://www.haomeiwen.com/subject/nakujftx.html