整理下安卓跳转通知设置页面的代码,如下:

常量补充:

private static final String CHECK_OP_NO_THROW = "checkOpNoThrow";private static final String OP_POST_NOTIFICATION = "OP_POST_NOTIFICATION";

1、android check通知是否开启代码

    public static boolean isNotificationEnabled(Context context) {if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {return isEnableV26(context);} else {return isEnableV19(context);}}/*** Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT* 19及以上** @param context* @return*/public static boolean isEnableV19(Context context) {AppOpsManager mAppOps = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE);ApplicationInfo appInfo = context.getApplicationInfo();String pkg = context.getApplicationContext().getPackageName();int uid = appInfo.uid;Class appOpsClass;try {appOpsClass = Class.forName(AppOpsManager.class.getName());Method checkOpNoThrowMethod = appOpsClass.getMethod(CHECK_OP_NO_THROW, Integer.TYPE, Integer.TYPE,String.class);Field opPostNotificationValue = appOpsClass.getDeclaredField(OP_POST_NOTIFICATION);int value = (Integer) opPostNotificationValue.get(Integer.class);return ((Integer) checkOpNoThrowMethod.invoke(mAppOps, value, uid, pkg) == AppOpsManager.MODE_ALLOWED);} catch (ClassNotFoundException e) {MyLog.e(sTAG, e);} catch (NoSuchMethodException e) {MyLog.e(sTAG, e);} catch (NoSuchFieldException e) {MyLog.e(sTAG, e);} catch (InvocationTargetException e) {MyLog.e(sTAG, e);} catch (IllegalAccessException e) {MyLog.e(sTAG, e);}return false;}/*** Build.VERSION.SDK_INT >= Build.VERSION_CODES.O* 针对8.0及以上设备** @param context* @return*/public static boolean isEnableV26(Context context) {try {NotificationManager notificationManager = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);Method sServiceField = notificationManager.getClass().getDeclaredMethod("getService");sServiceField.setAccessible(true);Object sService = sServiceField.invoke(notificationManager);ApplicationInfo appInfo = context.getApplicationInfo();String pkg = context.getApplicationContext().getPackageName();int uid = appInfo.uid;Method method = sService.getClass().getDeclaredMethod("areNotificationsEnabledForPackage", String.class, Integer.TYPE);method.setAccessible(true);return (boolean) method.invoke(sService, pkg, uid);} catch (Exception e) {MyLog.e(sTAG, e);}return false;}

2、跳转到通知页面

 public static void gotoNotificationSetting(Activity activity) {ApplicationInfo appInfo = activity.getApplicationInfo();String pkg = activity.getApplicationContext().getPackageName();int uid = appInfo.uid;try {if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {Intent intent = new Intent();intent.setAction(Settings.ACTION_APP_NOTIFICATION_SETTINGS);//这种方案适用于 API 26, 即8.0(含8.0)以上可以用intent.putExtra(Settings.EXTRA_APP_PACKAGE, pkg);intent.putExtra(Settings.EXTRA_CHANNEL_ID, uid);//这种方案适用于 API21——25,即 5.0——7.1 之间的版本可以使用intent.putExtra("app_package", pkg);intent.putExtra("app_uid", uid);activity.startActivityForResult(intent, AppConst.REQUEST_SETTING_NOTIFICATION);} else if (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:" + GlobalData.app().getPackageName()));activity.startActivityForResult(intent, AppConst.REQUEST_SETTING_NOTIFICATION);} else {Intent intent = new Intent(Settings.ACTION_SETTINGS);activity.startActivityForResult(intent, AppConst.REQUEST_SETTING_NOTIFICATION);}} catch (Exception e) {Intent intent = new Intent(Settings.ACTION_SETTINGS);activity.startActivityForResult(intent, AppConst.REQUEST_SETTING_NOTIFICATION);MyLog.e(sTAG, e);}}

3、但是目前存在两个已知问题。

(1)优购手机(UOOGOU T10  Android 5.1.1) check通知权限,关闭的通知权限, 也会isNotificationEnabled函数也会返回true,check权限不准,目前在排查,有结论了再在博客添加。

(2)小米手机部分系统跳转到通知设置页了,但是却屏蔽了开启按钮的显示。 很诡异。

我测试的问题手机是 米五(MIUI 9 8.4.27 开发板 Android 8.0.0) 和 小米6x (MIUI 10.0 稳定版 Android 8.1.0)

截图如下:

正常的截图

异常页面截图

如果大家说有更好地解决方案麻烦留言评论,谢谢。

android 跳转到应用通知设置界面【Android 8.0 需要特殊处理】相关推荐

  1. android 跳转系统通知,android 跳转到应用通知设置界面

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

  2. android 跳转oppo应用中心_android 跳转到应用通知设置界面的示例

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

  3. android跳转到像限设置界面,时间管理四象限法则 ToDo5.3 for Android体验

    你是否怀疑过,究竟什么占据了我们的时间?这是一个经常令人困惑的问题.著名科学家科维提出时间管理理论,把工作按照重要和紧急两个不同的程度进行了划分,分为既紧急又重要.重要但不紧急.紧急但不重要.既不紧急 ...

  4. Android:检查通知权限并跳转到通知设置界面

    声明:该方案只对API19及以上版本有效 一.目标需求 最近项目中在完善推送功能,需要进入APP时检测一下是否开启了推送权限,如果没有开启弹窗提醒,当用户点击弹窗时直接跳转到APP的通知设置界面,就像 ...

  5. APP跳转到系统Wifi设置界面方式

    测试手机:魅蓝note3 应用场景:打开手机APP,发现没有网络,点击"断网重连"按钮,跳转到系统WiFi设置界面,闪频一下,没有跳转成功.这是什么问题?贴代码 Intent in ...

  6. android自定义设置界面,Android开发之精仿QQ设置界面(自定义PreferenceActivity)

    Android开发之精仿QQ设置界面(自定义PreferenceActivity) 时间:2011-12-05 10:25:06 来源:Android开发者门户 作者: 今天,再给大家分享一下QQ设置 ...

  7. android编程获取网络和wifi状态及调用网络设置界面,Android编程获取网络连接状态(3G/Wifi)及调用网络配置界面 - Android平台开发技术 - 博客园...

    获取网络连接状态 随着3G和Wifi的推广,越来越多的Android应用程序需要调用网络资源,检测网络连接状态也就成为网络应用程序所必备的功能. Android平台提供了ConnectivityMan ...

  8. iOS在app里面跳转到系统的设置界面

    在需要调整的地方,添加如下代码: NSURL * url = [NSURLURLWithString:UIApplicationOpenSettingsURLString]: if([[UIAppli ...

  9. 【Android】通用系列 —— 快速搭建设置界面

    ## [关键词] `通用系列` `设置界面` `自定义View` ## [问题] · 减少重复性代码,快速搭建设置界面(通过简单的配置,就可以达到想要的布局): ## [效果图] ## [分析] - ...

最新文章

  1. android 严苛模式,Android- 严苛模式(StrictMode)
  2. 微信分享转发功能「PHP版」
  3. Unable to install breakpoint in Modify compiler options to generate line number attributes
  4. 自定义构建基于.net core 的基础镜像
  5. 30屏幕参数_顶级屏幕加持,一加8系列核心配置、屏幕参数官方公布
  6. [C++STL]C++实现stack容器适配器
  7. php视图查询的优势,ThinkPHP视图查询详解
  8. 非线性降维-核主成分分析KPCA
  9. OpenCV4每日一练day4:Mat类的创建、赋值、读取
  10. 在Vue 项目 webpack 打包中关于 背景图片的路径问题
  11. Linux下配置MySQL免安装版
  12. 《全局光照技术》在摩点网发起众筹活动
  13. overlay/static/register/atuo/extern/volatile/const 修饰符的用法
  14. 五线谱软件测试初学者,学习五线谱(初学者专用).pdf
  15. 机器人工程师技术资料
  16. python如何筛选excel重复_老板让我从上千个Excel中筛选数据,利用Python分分钟解决!...
  17. Wireshark之流量包分析+日志分析 (护网:蓝队)web安全 取证 分析黑客攻击流程(上篇)
  18. 过年抢红包,还怕手速慢,我用Python自动抢红包!
  19. 腾讯移动互联网事业群(MIG)综合分析
  20. C# 调用DXGI采集屏幕

热门文章

  1. 比Bootstrap还好用的CSS 框架 Bulma --教程
  2. 【cocos creator】编辑器里自动播放spine动画
  3. 计量经济学(十一)工具变量法
  4. matlab中ndgrid的意思,【ndgrid】什么意思_英语ndgrid的翻译_音标_读音_用法_例句_在线翻译_有道词典...
  5. 51单片机DS18B20测温数码管显示例程(Proteus仿真+程序)
  6. 永磁同步电机力矩控制(七):齿槽力矩
  7. Learning Python 008 正则表达式-004 sub()方法
  8. Neo4j 图数据库高级应用系列 / 服务器扩展指南 APOC (8.4) - 集合相关操作
  9. 可以修改常变量的值吗(c语言)
  10. 耶鲁大学开放课程:《聆听音乐》第8课