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

相关内容

热门资讯

wepoke辅助插件!wepo... wepoke辅助插件!wepoke辅助,(wepoke)切实有挂,德州论坛(黑科技工具)1、任何we...
德州线上外挂!德州之星透牌器,... 德州线上外挂!德州之星透牌器,(德州)总是是有挂,第三方教程(黑科技助手)1)德州之星透牌器辅助挂:...
德州之星有辅助挂吗!德州之星辅... 德州之星有辅助挂吗!德州之星辅助器怎么用,(德州ai)好像有挂,wpk教程(黑科技透明)小薇(透视辅...
微扑克ai代打!微扑克ai分析... 微扑克ai代打!微扑克ai分析器,(微扑克)确实是真的有挂,爆料教程(黑科技技巧)一、微扑克ai分析...
德扑之星ai代打!德扑ai智能... 德扑之星ai代打!德扑ai智能工具,(德扑)确实是真的有挂,2025新版总结(黑科技脚本);1、德扑...
aapoker辅助!aapok... aapoker辅助!aapoker系统机制,(AApoker)本来真的是有挂,总结教程(黑科技透视)...
wpk辅助插件!wpk ai辅... wpk辅助插件!wpk ai辅助,(wpK)其实真的有挂,wpk教程(黑科技系统)一、wpk辅助插件...
wpk怎么提高胜率!wpk辅助... wpk怎么提高胜率!wpk辅助器安装,(wPK)真是是真的有挂,玩家教你(黑科技方法)所有人都在同一...
微扑克辅助软件!wpk透视外挂... 微扑克辅助软件!wpk透视外挂,(wPk)确实是真的有挂,德州论坛(黑科技神器)1、完成微扑克辅助软...
wpk透视辅助是否真实存在!w... wpk透视辅助是否真实存在!wpk德州ai机器人,(WpK)总是是有挂,扑克教程(黑科技脚本)1、下...