Android打开当前应用的通知设置

try {

Intent intent = new Intent();

intent.setAction("android.settings.APP_NOTIFICATION_SETTINGS");

intent.putExtra("app_package", getPackageName());

intent.putExtra("app_uid", getApplicationInfo().uid);

startActivity(intent);

} catch (ActivityNotFoundException e) {

Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);

Uri uri = Uri.fromParts("package", getPackageName(), null);

intent.setData(uri);

startActivity(intent);

}

注:

先打开应用的通知设置页(5.0系统以上可用,但是非官方,不保证好用),如果打不开,就打开应用的设置页。


援引自 any-way-to-link-to-the-android-notification-settings-for-my-app

1) This intent relies oninternal/hiddencode of the Settings app, so there's no guarantee that in the future the Settings app won't change and no longer use the same String action, component, or Intent extras to open the app specific notification screen.

2) This method isnot completely backward compatible. The String action and components used were introduced about 2 years ago.

你可能感兴趣的:(Android打开当前应用的通知设置)