Android通知图标未显示
创始人
2024-08-21 19:30:14
0
  1. 确保通知权限已经启用。
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        NotificationChannel notificationChannel = new NotificationChannel("channel_id", "channel_name", NotificationManager.IMPORTANCE_HIGH);
        notificationManager.createNotificationChannel(notificationChannel);
}
  1. 如果您的应用是针对 API 26 或更高版本的,请确保通知渠道与通知中使用的通知 ID 匹配。
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        NotificationChannel notificationChannel = new NotificationChannel("channel_id", "channel_name", NotificationManager.IMPORTANCE_HIGH);
        NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        notificationManager.createNotificationChannel(notificationChannel);
        NotificationCompat.Builder builder = new NotificationCompat.Builder(this, "channel_id")
            .setSmallIcon(R.drawable.notification_icon)
            .setContentTitle("My notification")
            .setContentText("Hello World!")
            .setPriority(NotificationCompat.PRIORITY_HIGH)
            .setAutoCancel(true);
        Notification notification = builder.build();
        notificationManager.notify(1, notification);
 }
  1. 有些 ROM(如 MIUI)会自动隐藏通知图标。在这种情况下,您需要通过更改系统设置来使通知图标可见。
Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
intent.setData(Uri.fromParts("package", getPackageName(), null));
startActivity(intent);
  1. 如果您的应用是针对 API 21 或更高版本的,则可以使用以下代码来设置通知图标。
NotificationCompat.Builder builder = new NotificationCompat.Builder(this, "channel_id")
            .setSmallIcon(R.drawable.notification_icon)
            .setContentTitle("My notification")
            .setContentText("Hello World!")
            .setPriority(NotificationCompat.PRIORITY_HIGH)
            .setAutoCancel(true);
Notification notification = builder.build();
notificationManager.notify(1, notification);

相关内容

热门资讯

此事备受玩家关注"w... 此事备受玩家关注"wepoker有插件吗"哈糖大菠萝辅助器(都是是真的辅助神器)-哔哩哔哩1、下载好...
最终"hhpoker... 最终"hhpoker德州牛仔视频"wepoker透视有用吗(一直有辅助软件)-哔哩哔哩1、许多玩家不...
透视教学"wepok... 透视教学"wepoker手机版透视脚本"wepoker代打辅助(竟然有辅助神器)-哔哩哔哩1、wep...
透视透视"werpl... 透视透视"werplan免费挂下载"hhpoker辅助靠谱吗(竟然真的有辅助app)-哔哩哔哩1、让...
透视安装"破解辅助插... 透视安装"破解辅助插件wepoker"wepoker私人定制透视(本来真的有辅助神器)-哔哩哔哩1、...
来临"约局吧开挂&q... 来临"约局吧开挂"拱趴大菠萝有什么挂(切实真的是有辅助下载)-哔哩哔哩1、拱趴大菠萝有什么挂有没有辅...
透视代打"hhpok... 透视代打"hhpoker是正品吗"wepokerplus开挂(一贯是有辅助神器)-哔哩哔哩1、这是跨...
出现新变化"poke... 出现新变化"pokemmo手机版透视脚本"wepoker免费脚本咨询(真是有辅助app)-哔哩哔哩出...
昨日"wepoker... 昨日"wepoker有辅助插件吗"wepoker钻石怎么看底牌(果然是真的辅助修改器)-哔哩哔哩1、...
透视ai"wpk私人... 透视ai"wpk私人局辅助是真的吗"wepoker正确养号方法(竟然真的有辅助修改器)-哔哩哔哩1、...