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

相关内容

热门资讯

wpk德州ai辅助神器!wpk... wpk德州ai辅助神器!wpk有透视辅助吗,(wPk)本来有挂,软件教程(黑科技神器)1、在wpk德...
wpk德州透视外挂!wpk德州... wpk德州透视外挂!wpk德州透视外挂,(wpK)都是真的是有挂,AA德州教程(黑科技科技)该软件可...
AApoker透视辅助器安装教... AApoker透视辅助器安装教程!aapoker辅助器怎么用,(AApoker)总是存在有挂,专业教...
Wepoke黑科技设备!wep... Wepoke黑科技设备!wepoke透明挂哪里有,(WepOke)好像是有挂,我来教教你(黑科技辅助...
德扑ai助手!德扑ai智能机器... 德扑ai助手!德扑ai智能机器人代理,(德扑)竟然是真的有挂,详细教程(黑科技黑科技);一、德扑ai...
德扑之星ai代打风险分析!德扑... 德扑之星ai代打风险分析!德扑之星ai代打,(德扑之星)果然是真的有挂,力荐教程(黑科技插件)1)德...
德州ai购买!线上德州ai辅助... 德州ai购买!线上德州ai辅助,(德州ai)其实是有挂,揭秘教程(黑科技透视)1、很好的工具软件,可...
wepoke有没有挂!wepo... wepoke有没有挂!wepoke到底有没有挂,(we-poker)竟然真的有挂,科技教程(黑科技工...
AApoker辅助工具!aap... AApoker辅助工具!aapoker辅助实际测试,(AAPoker)原来真的有挂,力荐教程(黑科技...
微扑克ai软件!微扑克助手,(... 微扑克ai软件!微扑克助手,(微扑克)确实真的有挂,2025新版教程(黑科技透明挂)1、许多玩家不知...