Android应用程序没有请求通知权限。
创始人
2024-10-13 00:00:58
0

要求通知权限可以通过以下步骤实现:

  1. 在您的AndroidManifest.xml文件中添加以下代码,以请求通知权限:





    

    
        
            
        
    

  1. 在您的应用程序代码中,使用以下代码请求通知许可:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
    NotificationChannel channel = new NotificationChannel(CHANNEL_ID, "Channel human readable title", NotificationManager.IMPORTANCE_DEFAULT);
    notificationManager.createNotificationChannel(channel);
}

NotificationCompat.Builder builder = new NotificationCompat.Builder(this, CHANNEL_ID)
        .setSmallIcon(R.drawable.icon)
        .setContentTitle("My notification title")
        .setContentText("Hello World!")
        .setPriority(NotificationCompat.PRIORITY_DEFAULT);

// Show the notification
notificationManager.notify(notificationId, builder.build());
  1. 最后,要确保在用户打开应用程序时请求通知权限:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
    // Create channel to show notifications.
    String channelId = getString(R.string.default_notification_channel_id);
    String channelName = getString(R.string.default_notification_channel_name);
    notificationManager.createNotificationChannel(new NotificationChannel(channelId, channelName, NotificationManager.IMPORTANCE_HIGH));
}

// Notice that the id passed in is 0, it can be any integer you want,
// this is just your unique id for your notification
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
    NotificationChannel channel = notificationManager.getNotificationChannel(getString(R.string.default_notification_channel_id));
    if(channel.getImportance() == NotificationManager.IMPORTANCE_NONE) {
        Intent intent = new Intent(Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS);
        intent.putExtra(Settings.EXTRA_APP_PACKAGE, getPackageName());
        intent.putExtra(Settings.EXTRA_CHANNEL_ID, channel

相关内容

热门资讯

2024教程!wepoker怎... 1、2024教程!wepoker怎么增加运气,pokemmo脚本辅助下载,高科技教程(有挂辅助)。2...
盘点一款!We poker辅助... 盘点一款!We poker辅助器下载,hhpoker到底可以作弊吗,透明挂教程(有挂神器)是由北京得...
玩家必看攻略!we-poker... 《玩家必看攻略!we-poker是什么软件,aapoker怎么开辅助器,插件教程(有挂技巧)》 aa...
玩家必看科普!约局吧开挂神器是... 玩家必看科普!约局吧开挂神器是真的吗,wepoker好友助力码,力荐教程(有挂技巧);《WPK辅助透...
交流学习经验!werplan辅... 自定义wepoker辅助真的假的系统规律,只需要输入自己想要的开挂功能,一键便可以生成出微扑克专用辅...
教程辅助!wepoker有没有... 教程辅助!wepoker有没有挂,hhpoker是正品吗,技巧教程(有挂软件);《WPK辅助透视》‌...
最新通报!wepoker怎么设... 1、最新通报!wepoker怎么设置房间,wepoker辅助真的假的,AA德州教程(有挂教程)(UU...
热点讨论!hhpoker辅助器... 热点讨论!hhpoker辅助器,hh poker透视器下载,高科技教程(有挂透明);人气非常高,ai...
重大消息!wepoker透视苹... 重大消息!wepoker透视苹果系统,wepoker怎么设置盖牌,必胜教程(有挂技巧);人气非常高,...
交流学习经验!wepoker免... 交流学习经验!wepoker免费辅助器,hhpoker免费辅助器,辅助教程(有挂攻略);人气非常高,...