android 跳转到应用通知设置界面

4.4以下并没有提过从app跳转到应用通知设置页面的Action,可考虑跳转到应用详情页面,下面是直接跳转到应用通知设置的代码:

 if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                    Intent intent = new Intent();
                    intent.setAction("android.settings.APP_NOTIFICATION_SETTINGS");
                    intent.putExtra("app_package", getActivity().getPackageName());
                    intent.putExtra("app_uid", getActivity().getApplicationInfo().uid);
                    startActivity(intent);
                } else if (android.os.Build.VERSION.SDK_INT == Build.VERSION_CODES.KITKAT) {
                    Intent intent = new Intent();
                    intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
                    intent.addCategory(Intent.CATEGORY_DEFAULT);
                    intent.setData(Uri.parse("package:" + getActivity().getPackageName()));
                    startActivity(intent);
                }

跳转到应用详情页面的代码如下:

  Intent localIntent = new Intent();
                localIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                if (Build.VERSION.SDK_INT >= 9) {
                    localIntent.setAction("android.settings.APPLICATION_DETAILS_SETTINGS");
                    localIntent.setData(Uri.fromParts("package", getActivity().getPackageName(), null));
                } else if (Build.VERSION.SDK_INT <= 8) {
                    localIntent.setAction(Intent.ACTION_VIEW);
                    localIntent.setClassName("com.android.settings", "com.android.settings.InstalledAppDetails");
                    localIntent.putExtra("com.android.settings.ApplicationPkgName", getActivity().getPackageName());
                }
                startActivity(localIntent);

对于检测app是否开启通知,同样是针对4.4以上的系统才有效:

NotificationManagerCompat manager = NotificationManagerCompat.from(App.getInstance().getContext());
boolean isOpened = manager.areNotificationsEnabled();

4.4以下调用该方法并不会出错,只是全部返回true,默认开启状态

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 175,261评论 25 709
  • 发现 关注 消息 iOS 第三方库、插件、知名博客总结 作者大灰狼的小绵羊哥哥关注 2017.06.26 09:4...
    肇东周阅读 14,196评论 4 61
  • 我是一株灵纤草,从单细胞到现在的含苞待放,我走了三万年,在我看来,生是对我最大的惩罚,我最大的愿望就是离...
    灵纤草阅读 1,943评论 1 2
  • 旅行的意义是什么?应该是遇见不同的人,亨受当地美食,感受当地的风土人情,从而感知生活的多样及美好,远方有诗,忘记自...
    光耀初照阅读 2,833评论 7 6
  • 欢迎前往个人博客 驽马点滴 和视频空间 哔哩哔哩-《挨踢日志》 序言 在开发的过程中,我们会遇到这样的一些需求: ...
    KomalZheng阅读 5,043评论 0 0