美文网首页
Android打开当前应用的通知设置

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

作者: 言者无知_n4c | 来源:发表于2017-01-12 14:40 被阅读0次

    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打开当前应用的通知设置

          本文链接:https://www.haomeiwen.com/subject/lewdbttx.html