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、操作简单,无需注册,只需...
黑科技辅助挂!(红龙扑克)辅助... 黑科技辅助挂!(红龙扑克)辅助器工具,(红龙扑克)一贯有挂,必胜教程(有挂插件)一、红龙扑克软件透明...
黑科技辅助挂!(WPK)一贯有... 黑科技辅助挂!(WPK)一贯有挂,(wPk)都是是真的有挂,攻略教程(有挂攻略);1、金币登录送、破...
黑科技辅助挂!wPK透视辅助,... 黑科技辅助挂!wPK透视辅助,(WpK)本来存在有挂,切实教程(有挂透明挂)1)WpK辅助挂:进一步...
黑科技辅助挂!(红龙扑克)果然... 黑科技辅助挂!(红龙扑克)果然是有挂,(红龙扑克)确实是有挂,安装教程(有挂软件)1、任何红龙扑克a...
黑科技辅助挂!(AAPoker... 黑科技辅助挂!(AAPoker)都是存在有挂,(AAPoKER)一直有挂,黑科技教程(有挂科技)1、...
黑科技辅助挂!(WePoke)... 黑科技辅助挂!(WePoke)一直是真的有挂,(WEPOke)一直是有挂,透明教程(有挂助手)1)W...
黑科技辅助挂!wepOKE软件... 黑科技辅助挂!wepOKE软件透明挂,WEpoke透明挂ai代打,解密教程(有挂系统)1、全新机制【...
黑科技辅助挂!WPk透视辅助,... 黑科技辅助挂!WPk透视辅助,wPk透视辅助在哪下,详细教程(有挂透明挂)1、玩家可以在wPk软件透...
黑科技辅助挂!微扑克透视辅助,... 黑科技辅助挂!微扑克透视辅助,(Wpk)其实真的是有挂,微扑克教程(有挂工具)1、黑科技辅助挂!微扑...