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

相关内容

热门资讯

wepower有外挂!aapo... 这是一款非常优秀的wepower有外挂 ia辅助检测软件,能够让你了解到wepower有外挂中牌率当...
透视神器(德州之星辅助)德扑之... 透视神器(德州之星辅助)德扑之星可以看底牌吗(详细辅助新2025版)起初真的有挂1、这是跨平台的德州...
透视辅助(wpk有透视辅助)德... 透视辅助(wpk有透视辅助)德扑之星真的太假了(详细辅助实用技巧)起初真的有挂您好,wpk有透视辅助...
wepoke辅助插件!wepo... wepoke辅助插件!wepower怎么设置德州,(德州)原本是有挂(详细透视技巧教程)1、点击下载...
透视辅助(wepoke辅助)德... 透视辅助(wepoke辅助)德州ai软件是什么样(详细辅助切实教程)一向有挂是一款可以让一直输的玩家...
德州之星有外挂!德扑之星实战,... 德州之星有外挂!德扑之星实战,(wePOKE)总是是有挂(详细透视可靠教程);原来确实真的有挂(需添...
透视黑科技(wepoke一定有... 透视黑科技(wepoke一定有挂)德州游戏辅助器大全(详细辅助教你攻略)一直是真的有挂1、不需要AI...
微扑克游戏辅助器!微扑克辅助机... 微扑克游戏辅助器!微扑克辅助机器人,(AAPOKer)其实是有挂(详细辅助必胜教程);小薇(透视辅助...
透视好友房(wepoke有没有... 透视好友房(wepoke有没有挂)德扑ai软件购买(详细辅助科技教程)一直真的有挂1、超多福利:超高...
wepoke辅助插件!德州nz... wepoke辅助插件!德州nzt实战,(WpK)本来是真的有挂(详细辅助科技教程);1.wepoke...