LoginSignup
6
6

More than 5 years have passed since last update.

AndroidでアプリからOSの通知設定画面を開く

Posted at

AndroidでアプリからOSの通知設定画面を開く

if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
    Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS,
                               Uri.parse("package:" + BuildConfig.APPLICATION_ID));
    // カテゴリは設定しなくてもいいかも
    intent.addCategory(Intent.CATEGORY_DEFAULT);
    // Flagは好みで設定
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
    startActivity(intent);
} else {
    Intent intent = new Intent(Settings.ACTION_APP_NOTIFICATION_SETTINGS);
    // カテゴリは設定しなくてもいいかも
    intent.addCategory(Intent.CATEGORY_DEFAULT);
    // Flagは好みで設定
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);

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

    // for Android O
    intent.putExtra("android.provider.extra.APP_PACKAGE", BuildConfig.APPLICATION_ID);

    startActivity(intent);

6
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
6