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机器人!微扑克游戏辅... 微扑克ai机器人!微扑克游戏辅助器,(德州微扑克)确实有挂(详细辅助器ios教程);微扑克游戏辅助器...
aapoker辅助!aapok... aapoker辅助!aapoker辅助工具存在吗,(aapoker)竟然存在有挂(详细辅助教程);1...
微扑克有辅助挂!微扑克透明挂,... 微扑克有辅助挂!微扑克透明挂,(微扑克稳赢)一直是有挂(详细ai机器人教程);玩家在微扑克有辅助挂中...
德扑ai怎么系统!德扑ai机器... 相信很多朋友都在电脑上玩过吧,但是很多朋友都在抱怨用电脑玩起来不方便。为此小编给大家带来了手机版,这...
德州之星有辅助挂!德扑之星如何... 德州之星有辅助挂!德扑之星如何分别是否,德扑ai人工智能一直是有挂(详细专业教程);人气非常高,ai...
红龙扑克辅助工具!红龙扑克有挂... 红龙扑克辅助工具!红龙扑克有挂么,(红龙扑克)本来存在有挂(详细辅助挂教程)1、这是跨平台的黑科技,...
微扑克有辅助挂!微扑克ai辅助... 微扑克有辅助挂!微扑克ai辅助神器,(微扑克操作)切实真的是有挂(详细辅助软件教程)是一款可以让一直...
德扑之星猫腻!德扑ai软件,德... 德扑之星猫腻!德扑ai软件,德扑ai购买其实是真的有挂(详细开发教程)科技教程也叫必备教程,这是一款...
aapoker猫腻!aapok... aapoker猫腻!aapoker ai软件,(aapoker讲解)竟然真的有挂(详细辅助教程);a...
aapoker俱乐部!aapo... aapoker俱乐部!aapoker俱乐部,(aapker代理)好像是有挂(详细挂教程);aapok...