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透视... 您好,新九天辅助这款游戏可以开挂的,确实是有挂的,需要了解加去威信【136704302】很多玩家在这...
透视模块!约局吧app有挂吗(... 透视模块!约局吧app有挂吗(透视)pokerrrr2辅助(辅助)真是一直都是有教程(哔哩哔哩)1、...
据目击者称!德州局透视(透视)... 据目击者称!德州局透视(透视)九天大厅辅助器(本来真的是有辅助app)-哔哩哔哩1、玩家可以在九天大...
透视操作!竞技联盟透视插件(透... 透视操作!竞技联盟透视插件(透视)智星德州插件2024最新版(辅助)一直一直总是有app(哔哩哔哩)...
透视有挂!wepoker钻石怎... 透视有挂!wepoker钻石怎么看底牌(透视)菠萝辅助器免费版的功能介绍(竟然存在有辅助下载)-哔哩...
透视模块!菠萝德州透视脚本(透... 透视模块!菠萝德州透视脚本(透视)epoker透视(辅助)总是有工具(哔哩哔哩)菠萝德州透视脚本脚本...
据目击者称!hhpoker透视... 据目击者称!hhpoker透视脚本视频(透视)激k辅助器有挂吗(都是存在有辅助安装)-哔哩哔哩1、许...
透视办法!来玩app 德州 辅... 透视办法!来玩app 德州 辅助(透视)哈糖大菠萝助手(辅助)原来一直总是有攻略(哔哩哔哩)透视办法...
透视真的!wepoker私人局... 透视真的!wepoker私人局可以透视(透视)微乐锄大地脚本(一直真的是有辅助软件)-哔哩哔哩透视真...
透视教程书!德州圈脚本(透视)... 透视教程书!德州圈脚本(透视)拱趴大菠萝自动计算机器人(辅助)确实是有插件(哔哩哔哩)拱趴大菠萝自动...