有什么方法可以链接到我的应用程序的 Android 通知设置? [英] Any way to link to the Android notification settings for my app?

查看:29
本文介绍了有什么方法可以链接到我的应用程序的 Android 通知设置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么方法可以启动 Intent 以访问我的应用的 Android 通知设置屏幕(如下图所示)?或者我可以制作一个 PreferenceScreen 项目的简单方法,只需点击一下就可以引导到这里?

Is there any way I can launch an intent to get to Android's notification settings screen for my app (pictured below)? Or an easy way I can make a PreferenceScreen item that just leads here on a click?

推荐答案

以下适用于 Android 5.0 (Lollipop) 及更高版本:

The following will work in Android 5.0 (Lollipop) and above:

Intent intent = new Intent();
intent.setAction("android.settings.APP_NOTIFICATION_SETTINGS");

//for Android 5-7
intent.putExtra("app_package", getPackageName());
intent.putExtra("app_uid", getApplicationInfo().uid);

// for Android 8 and above
intent.putExtra("android.provider.extra.APP_PACKAGE", getPackageName());

startActivity(intent);

注意:这在 Android 5-7 中没有得到官方支持,但它工作得很好.从 Android 8 开始正式支持它.此代码不向后兼容 5.0 之前的 Android 版本.

Notes: This is not officially supported in Android 5-7, but it works just fine. It IS officially supported as of Android 8. This code is not backwards compatible with versions of Android before 5.0.

这篇关于有什么方法可以链接到我的应用程序的 Android 通知设置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆