boolean areNotificationsEnabled = mNotificationManagerCompat.areNotificationsEnabled();        if (!areNotificationsEnabled) {            // Because the user took an action to create a notification, we create a prompt to let            // the user re-enable notifications for this application again.            Snackbar snackbar = Snackbar                    .make(                            mMainRelativeLayout,                            "You need to enable notifications for this app",                            Snackbar.LENGTH_LONG)                    .setAction("ENABLE", new View.OnClickListener() {                        @Override                        public void onClick(View view) {                            // Links to this app's notification settings                            openNotificationSettingsForApp();                        }                    });            snackbar.show();            return;        }

首先通过areNotificationsEnabled查询应用是否有通知权限,如果没有则执行openNotificationSettingsForApp()方法。

private void openNotificationSettingsForApp() {     // Links to this app's notification settings.     Intent intent = new Intent();     intent.setAction(Settings.ACTION_APP_NOTIFICATION_SETTINGS);     //这种方案适用于 API 26, 即8.0(含8.0)以上可以用     intent.putExtra(Settings.EXTRA_APP_PACKAGE, getApplicationContext().getPackageName());     intent.putExtra(Settings.EXTRA_CHANNEL_ID, getApplicationInfo().uid);     //这种方案适用于 API21——25,即 5.0——7.1 之间的版本可以使用     intent.putExtra("app_package", pkg);     intent.putExtra("app_uid", uid);     startActivity(intent); }

通过intent启动系统应用的通知管理界面。

更多相关文章

  1. android 开发中java.net.UnknownServiceException: CLEARTEXT co
  2. Android实现推送方式解决方案
  3. Android屏幕适配终极方案-原理篇
  4. Android 状态栏通知Notification(转载)
  5. android通知栏之Notification的使用
  6. (mac)Android Studio安装以及Fetching android sdk component in
  7. 【Android 开发】:通知之Notifications Toast

随机推荐

  1. Android源代码下载指南(图解)
  2. 关于android使用已有id,自己的id和系统id
  3. 模拟Android多点触控
  4. android中LayoutInflater的使用
  5. Android(安卓)studio获取sha1(调试版和发
  6. android的UI系统分析
  7. Android(安卓)开发学习小结(七)
  8. Android(安卓)模拟器的认识
  9. android sdk API level对应关系及下载地
  10. 我的Android进阶之旅------>Android利用