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、微扑克游戏辅...
发现玩家!微扑克有脚本吗,微扑... 发现玩家!微扑克有脚本吗,微扑克如何让系统发好牌(微扑克)好像真的有挂(有挂讲解)-哔哩哔哩;在进入...
教程辅助!微扑克辅助测试,微扑... 教程辅助!微扑克辅助测试,微扑克ai机器人(微扑克)切实存在有挂(有挂规律)-哔哩哔哩进入游戏-大厅...
最新通报!微扑克辅助挂,微扑克... 最新通报!微扑克辅助挂,微扑克透牌(微扑克)好像存在有挂(有挂透明挂)-哔哩哔哩1、微扑克辅助挂透视...
技术分享!微扑克代打是真的吗,... 技术分享!微扑克代打是真的吗,微扑克透牌(微扑克)真是是真的有挂(有挂工具)-哔哩哔哩1、微扑克代打...
第六分钟辅助挂!微信闲来辅助神... 第六分钟辅助挂!微信闲来辅助神器app(透视)四川熊猫辅助软件(详细透视外开挂教程)是一款可以让一直...
6分钟辅助挂!兴动互娱辅助脚本... 6分钟辅助挂!兴动互娱辅助脚本(透视)人人燕赵辅助(详细透视外开挂教程);兴动互娱辅助脚本是一种具有...
第7分钟辅助挂!川南小闲辅助器... 1、第7分钟辅助挂!川南小闲辅助器(透视)蜀山四川智能辅助插件(详细透视外开挂教程);代表性(透视辅...
七分钟辅助挂!皮皮游戏挂机辅助... 七分钟辅助挂!皮皮游戏挂机辅助(透视)情怀蒲仙辅助(详细透视外开挂教程)1)皮皮游戏挂机辅助辅助挂:...