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

相关内容

热门资讯

黑科技安卓版(wepokeai... 黑科技安卓版(wepokeai代打)外挂黑科技辅助方法(透视)竟然是真的有挂(黑科技介绍)1、游戏颠...
黑科技线上(wpk有辅助挂)外... 黑科技线上(wpk有辅助挂)外挂黑科技辅助挂(透视)一直是真的有挂(黑科技方法)1、点击下载安装,w...
黑科技辅助挂(德扑之星辅助工具... 黑科技辅助挂(德扑之星辅助工具)外挂透明挂辅助插件(透视)切实真的有挂(黑科技规律);1、德扑之星辅...
黑科技系统(微扑克系统发牌逻辑... 黑科技系统(微扑克系统发牌逻辑)外挂透明挂辅助神器(透视)确实真的有挂(黑科技技巧)1、任何微扑克系...
黑科技线上(WePoKe透明挂... 黑科技线上(WePoKe透明挂)外挂透明挂辅助安装(透视)本来是真的有挂(黑科技辅助)1)WePoK...
黑科技讲解(微扑克辅助神器)外... 黑科技讲解(微扑克辅助神器)外挂黑科技辅助器(透视)好像存在有挂(黑科技规律)1、微扑克辅助神器ai...
黑科技美元局(德扑之星软件有猫... 黑科技美元局(德扑之星软件有猫腻吗)外挂黑科技辅助教程(透视)好像真的有挂(黑科技细节)1、金币登录...
黑科技辅助(微扑克辅助器ios... 黑科技辅助(微扑克辅助器ios)外挂透明挂辅助助手(透视)总是是有挂(黑科技揭秘)小薇(透视辅助)致...
黑科技私人局(德州ai辅助有用... 黑科技私人局(德州ai辅助有用)外挂透视辅助下载(透视)一直是有挂(黑科技黑科技)1、德州ai辅助有...
黑科技总结(德州之星辅助器多少... 黑科技总结(德州之星辅助器多少钱)外挂黑科技辅助助手(透视)切实存在有挂(黑科技方法);1、这是跨平...