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

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

问题描述

有什么方法可以启动我的应用程序以进入我的应用程序的Android通知设置屏幕(如下图所示)吗?或者,我可以通过一种简单的方法制作一个PreferenceScreen项,使其在单击时就可以引向此处?

解决方案

以下内容将在Android 5.0(棒棒糖)及更高版本中运行:

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版本不向后兼容.

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?

解决方案

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);

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天全站免登陆