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透视辅助可测... 黑科技透视!wpk透视辅助可测试真的假的,德州之星有外挂吗,我来教教你(有挂透明)-哔哩哔哩;黑科技...
黑科技神器!we-poker有... 黑科技神器!we-poker有挂吗,aapoker有内部好嘛,线上教程(有挂详情)-哔哩哔哩;人气非...
黑科技辅助挂!wepoke有辅... 黑科技辅助挂!wepoke有辅助挂,德扑之星软件,2025新版教程(有挂方法)-哔哩哔哩1.wepo...
黑科技软件!智星德州菠萝怎么看... 黑科技软件!智星德州菠萝怎么看有没有开挂,微扑克有辅助挂,安装教程(有挂介绍)-哔哩哔哩1、超多福利...
黑科技透明挂!wepoke黑科... 黑科技透明挂!wepoke黑科技,微扑克ai辅助神器,新2025版(有挂详情)-哔哩哔哩;无聊就玩这...
黑科技神器!德州之星有机器人吗... 黑科技神器!德州之星有机器人吗,德扑之星软件有猫腻吗,wepoke教程(有挂黑科技)-哔哩哔哩;黑科...
黑科技挂!wepoke软件透明... 黑科技挂!wepoke软件透明挂价格,智星德州菠萝辅助器,辅助教程(有挂规律)-哔哩哔哩;黑科技挂!...
黑科技脚本!wepoke透明挂... 一、wepoke透明挂是真的吗简介了解软件请加微:136704302wepoke透明挂是真的吗是一款...
黑科技脚本!德州ai辅助外挂,... 黑科技脚本!德州ai辅助外挂,红龙扑克辅助器下载,2025新版(有挂教程)-哔哩哔哩1、不需要AI权...
黑科技软件!德扑之星软件模拟器... 黑科技软件!德扑之星软件模拟器,wepower有外挂,详细教程(有挂黑科技)-哔哩哔哩是一款可以让一...