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

相关内容

热门资讯

黑科技游戏!来玩app有挂吗(... 黑科技游戏!来玩app有挂吗(透视)真是有挂(有挂大厅)-哔哩哔哩;1分钟了解详细教程(微信 136...
黑科技辅助!线上德州辅助软件有... 黑科技辅助!线上德州辅助软件有用吗(辅助挂)原来是有挂(有挂长期)-哔哩哔哩;线上德州辅助软件有用吗...
黑科技教学!微扑克微乐辅助(透... 黑科技教学!微扑克微乐辅助(透明挂)本然真的有挂(有挂线上)-哔哩哔哩;支持多人共享记分板与复盘,通...
黑科技科技!德州aa辅助(ai... 黑科技科技!德州aa辅助(ai辅助)原来真的有挂(有挂模拟器)-哔哩哔哩准备好在德州aa辅助ia的高...
黑科技辅助挂!微扑克辅助哪里有... 1、黑科技辅助挂!微扑克辅助哪里有卖(透明挂)本来是真的有挂(有挂游戏)-哔哩哔哩(UU poker...
黑科技代打!德州wpk辅助是否... 黑科技代打!德州wpk辅助是否真实存在(黑科技)确实是有挂(有挂德州)-哔哩哔哩;科技安装教程;13...
黑科技真的!微扑克软件发牌原理... 黑科技真的!微扑克软件发牌原理(透明挂)从来有挂(有挂最新版)-哔哩哔哩是一款可以让一直输的玩家,快...
黑科技工具!aapoker这个... 黑科技工具!aapoker这个软件靠谱吗(透明挂)原先有挂(有挂开挂)-哔哩哔哩;aapoker这个...
黑科技苹果版!we-poker... 此外,数据分析德州(we-poker ai怎么用)辅助神器app还具备辅助透视行为开挂功能,通过对客...
黑科技规律!wepoke软件透... 此外,数据分析德州(wepoke软件透明挂演示)辅助神器app还具备辅助透视行为开挂功能,通过对客户...