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

相关内容

热门资讯

教程辅助(德扑之星破解)外挂透... 教程辅助(德扑之星破解)外挂透明挂辅助APP(辅助挂)辅助透视(2021已更新)(哔哩哔哩);超受欢...
透视ai代打(poker wo... 1、透视ai代打(poker world外挂)外挂透明挂辅助脚本(辅助挂)发牌规律(确实有挂)-哔哩...
玩家必备科普!德州微扑克专用(... 自定义德州微扑克专用系统规律,只需要输入自己想要的开挂功能,一键便可以生成出微扑克专用辅助器,不管你...
揭秘关于(aapoker安卓版... 揭秘关于(aapoker安卓版)外挂透明挂辅助APP(透视)辅助透视(2025已更新)(哔哩哔哩);...
推荐攻略(wePoKe)外挂透... 推荐攻略(wePoKe)外挂透明挂辅助器安装(辅助挂)发牌机制(有挂细节)-哔哩哔哩;致您一封信;亲...
实测分享!WPK俱乐部(Wep... 实测分享!WPK俱乐部(Wepoke)外挂透明挂辅助器(透视)wepoke教程(有挂细节)-哔哩哔哩...
每日必看教程(鱼扑克发牌规律)... 每日必看教程(鱼扑克发牌规律)外挂透明挂辅助器安装(透视)辅助透视(2020已更新)(哔哩哔哩);鱼...
重大来袭(we-poke)外挂... 重大来袭(we-poke)外挂透明挂辅助脚本(辅助挂)发牌规律(有挂分析)-哔哩哔哩1、很好的工具软...
透明肯定!德扑之星底牌(wep... 透明肯定!德扑之星底牌(wepoke)外挂透明挂辅助APP(辅助挂)安装教程(有挂细节)-哔哩哔哩;...
程序员教你(WPK开发)外挂透... WePoker透视辅助工具核心要点解析‌,程序员教你(WPK开发)外挂透明挂辅助机制(透视)透视辅助...