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

相关内容

热门资讯

透视ai(we辅助poker德... 透视ai(we辅助poker德之星)wpk ai是什么(详细辅助揭秘教程)素来真的是有挂(1)透视a...
wepoke辅助挂!wopok... wepoke辅助挂!wopoker德州真的有挂吗,(WepOke)固有是真的有挂(详细辅助专业教程)...
透视ai(wepoke一定有挂... 透视ai(wepoke一定有挂)德州游戏辅助器大全(详细辅助曝光教程)一直有挂1、打开德州poker...
wepoke辅助!微扑克微乐辅... wepoke辅助!微扑克微乐辅助,(德州扑克)素来存在有挂(详细辅助新版2025教程);(需添加指定...
透视神器(aapoker有猫腻... 透视神器(aapoker有猫腻)云扑克辅助透视(详细辅助解密教程)最初是真的有挂1、每个玩家都可以进...
wpk真的有外挂!红龙扑克电脑... wpk真的有外挂!红龙扑克电脑模拟器,(wepOkE)一向真的是有挂(详细透视科技教程);致您一封信...
透视软件(aapoker猫腻)... 您好,这款游戏可以开挂的,确实是有挂的,需要了解加微【136704302】很多玩家在这款游戏中打牌都...
we辅助poker德之星!德州... we辅助poker德之星!德州ai智能辅助,(wepoKe)原先真的有挂(详细辅助wpk教程);大神...
透视透视(wepoke智能ai... 一、简介了解软件请加微:136704302是一款在线扑克游戏平台,玩家可以在平台上进行多人在线扑克游...
wepoke辅助机器人!菠萝德... wepoke辅助机器人!菠萝德州app挂哪里买,(wEpOke)原来是真的有挂(详细辅助解密教程)是...