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

相关内容

热门资讯

黑科技攻略(德扑之星软件有猫腻... 黑科技攻略(德扑之星软件有猫腻吗)外挂透明挂辅助挂(透视)其实存在有挂(黑科技解密);1、德扑之星软...
黑科技脚本(德州之星辅助软件介... 黑科技脚本(德州之星辅助软件介绍)外挂透视辅助神器(透视)好像是有挂(黑科技介绍)1、许多玩家不知道...
黑科技辅助挂(wepoke辅助... 黑科技辅助挂(wepoke辅助德之星)外挂透明挂辅助下载(透视)好像真的是有挂(黑科技脚本)1、许多...
黑科技安卓版(wepoke辅助... 黑科技安卓版(wepoke辅助使用方法)外挂黑科技辅助挂(透视)原来真的是有挂(黑科技规律)1)we...
黑科技安卓版(智星德州菠萝怎么... 黑科技安卓版(智星德州菠萝怎么看有没有开挂)外挂黑科技辅助软件(透视)本来是有挂(黑科技解密);1....
黑科技存在(德扑ai助手)外挂... 黑科技存在(德扑ai助手)外挂黑科技辅助教程(透视)真是是有挂(黑科技教程);1、很好的工具软件,可...
黑科技工具(wpk辅助插件)外... 黑科技工具(wpk辅助插件)外挂黑科技辅助下载(透视)切实是真的有挂(黑科技规律)1、wpk辅助插件...
黑科技新版(aa扑克外挂)外挂... 黑科技新版(aa扑克外挂)外挂黑科技辅助挂(透视)原来是有挂(黑科技脚本)1、aa扑克外挂系统规律教...
黑科技ai(aapoker猫腻... 黑科技ai(aapoker猫腻)外挂黑科技辅助挂(透视)切实是真的有挂(黑科技攻略);所有人都在同一...
黑科技免费(wepoke算法)... 黑科技免费(wepoke算法)外挂黑科技辅助助手(透视)原来有挂(黑科技辅助)进入游戏-大厅左侧-新...