Android 判断应用是否开启了通知权限
16lz
2021-01-23
Android 判断是否开启了应用权限
- 判断是否开启应用权限方法
- 如果没有开启应用权限,引导用户点击开启按钮,然后跳转到系统设置界面
判断是否开启应用权限方法
NotificationManagerCompat.from(context).areNotificationsEnabled();
如果没有开启应用权限,引导用户点击开启按钮,然后跳转到系统设置界面
private void goToSetting() { Intent intent = new Intent(); if (Build.VERSION.SDK_INT >= 26) {// android 8.0引导 intent.setAction("android.settings.APP_NOTIFICATION_SETTINGS"); intent.putExtra("android.provider.extra.APP_PACKAGE", getPackageName()); } else if (Build.VERSION.SDK_INT >= 21) { // android 5.0-7.0 intent.setAction("android.settings.APP_NOTIFICATION_SETTINGS"); intent.putExtra("app_package", getPackageName()); intent.putExtra("app_uid", getApplicationInfo().uid); } else {//其它 intent.setAction("android.settings.APPLICATION_DETAILS_SETTINGS"); intent.setData(Uri.fromParts("package", getPackageName(), null)); } intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(intent);}
更多相关文章
- appwidget中使按钮不能用 以及 appwidget初学指导
- 【Android】1.6版本所有权限
- Android 危险权限与所有权限大全
- Android 4.0为Launcher主界面所有应用程序图标添加统一背景主题
- Android控件ToggleButton多状态按钮使用详解
- Android基础:去掉app界面的标题-Title
- android 应用程序跳转到Settings的各个界面