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);

相关内容

热门资讯

受玩家影响!wepoker永久... 受玩家影响!wepoker永久免费脚本,德扑圈有透视吗,其实确实有挂(有挂教程)1、让任何用户在无需...
现有说明如下!pokemmo辅... 现有说明如下!pokemmo辅助器,红龙poker辅助,果然真的是有挂(确实有挂)所有人都在同一条线...
代打辅助挂!wepoker免费... 代打辅助挂!wepoker免费辅助器,德扑圈透视,总是是真的有挂(果真有挂)1、德扑圈透视免费辅助多...
黑科技插件!德普辅助软件,德扑... 您好,德扑之星怎么设置埋牌这款游戏可以开挂的,确实是有挂的,需要了解加去威信【136704302】很...
今年以来!cloudpoker... 今年以来!cloudpoker怎么开挂,德扑之星私人局辅助器,确实是有挂(有挂教程)1、全新机制【德...
迎来新发展!pokemmo辅助... 迎来新发展!pokemmo辅助工具,德普之星透视辅助软件,好像是真的有挂(有挂工具)德普之星透视辅助...
做出回应!wpk作弊最怕三个东... 做出回应!wpk作弊最怕三个东西,智星德州插件,竟然真的有挂(有挂神器)1、上手简单,内置详细流程视...
有了最新消息!wepoker买... 有了最新消息!wepoker买钻石有用吗,德普辅助软件,都是是真的有挂(了解有挂)德普辅助软件脚本下...
近期!hhpoker为什么一直... 近期!hhpoker为什么一直输,智星德州插件2024最新版,真是是真的有挂(了解有挂)1、下载好智...
据报道!wepoker透视有吗... 据报道!wepoker透视有吗,德扑之星怎么开辅助,一直真的是有挂(有挂实锤)1、许多玩家不知道德扑...