How can I programmatically open the permission screen for a specific app on Android 6.0 (Marshmallow)?

AndroidAndroid PermissionsAndroid 6.0-Marshmallow

Android Problem Overview


I have a question regarding the new Android 6.0 (Marshmallow) release:

Is it achievable to display the permission screen for a specific app via an Intent or something similar?

Android M Permission Screen

It's possible to display the app settings with the following code - is there an analog solution for directly opening the permission screen?

startActivity(new Intent(android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS,
Uri.fromParts("package", getPackageName(), null)));

I already did some research on this, but I wasn't able to find a proper solution.

Android Solutions


Solution 1 - Android

According to the official Marshmallow permissions video (at the 4m 43s mark), you must open the application Settings page instead (from there it is one click to the Permissions page).

To open the settings page, you would do

Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
Uri uri = Uri.fromParts("package", getPackageName(), null);
intent.setData(uri);
startActivity(intent);

Solution 2 - Android

This is not possible. I tried to do so, too. I could figure out the package name and the activity which will be started. But in the end you will get a security exception because of a missing permission you can't declare.

UPDATE:

Regarding the other answer I also recommend to open the App settings screen. I do this with the following code:

    public static void startInstalledAppDetailsActivity(final Activity context) {
    if (context == null) {
        return;
    }
    final Intent i = new Intent();
    i.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
    i.addCategory(Intent.CATEGORY_DEFAULT);
    i.setData(Uri.parse("package:" + context.getPackageName()));
    i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    i.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
    i.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
    context.startActivity(i);
}

As I don't want to have this in my history stack I remove it using intent flags.

Solution 3 - Android

Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Uri uri = Uri.fromParts("package", getPackageName(), null);
intent.setData(uri);
startActivity(intent);

Description

Settings.ACTION_APPLICATION_DETAILS_SETTINGS
   Opens Details setting page for App. From here user have to manually assign desired permission.

Intent.FLAG_ACTIVITY_NEW_TASK
   Optional. If set then opens Settings Screen(Activity) as new activity. Otherwise, it will be opened in currently running activity.

Uri.fromParts("package", getPackageName(), null)
   Prepares or creates URI, whereas, getPackageName() - returns name of your application package.

intent.setData(uri)
   Don't forget to set this. Otherwise, you will get android.content.ActivityNotFoundException. Because you have set your intent as Settings.ACTION_APPLICATION_DETAILS_SETTINGS and android expects some name to search.

Solution 4 - Android

Instead, you can open a particular app's general settings with one line:

 startActivity(new Intent(android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS, Uri.parse("package:" + BuildConfig.APPLICATION_ID)));

Solution 5 - Android

If you want to write less code in Kotlin you can do this:

fun Context.openAppSystemSettings() {
    startActivity(Intent().apply {
        action = Settings.ACTION_APPLICATION_DETAILS_SETTINGS
        data = Uri.fromParts("package", packageName, null)
    })
}

Based on Martin Konecny answer

Solution 6 - Android

Kotlin style.

startActivity(Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS).apply {
    data = Uri.fromParts("package", packageName, null)
})

Solution 7 - Android

It is not possible to programmatically open the permission screen. Instead, we can open the app settings screen.

Code

Intent i = new Intent(android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS, Uri.parse("package:" + BuildConfig.APPLICATION_ID));
startActivity(i);

Sample Output

enter image description here

Solution 8 - Android

Starting with Android 11, you can directly bring up the app-specific settings page for the location permission only using code like this: requestPermissions(arrayOf(Manifest.permission.ACCESS_BACKGROUND_LOCATION), PERMISSION_REQUEST_BACKGROUND_LOCATION)

However, the above will only work one time. If the user denies the permission or even accidentally dismisses the screen, the app can never trigger this to come up again.

Other than the above, the answer remains the same as prior to Android 11 -- the best you can do is bring up the app-specific settings page and ask the user to drill down two levels manually to enable the proper permission.

val intent = Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS)
val uri: Uri = Uri.fromParts("package", packageName, null)
intent.data = uri
// This will take the user to a page where they have to click twice to drill down to grant the permission
startActivity(intent)

See my related question here: https://stackoverflow.com/questions/64246883/android-11-users-can-t-grant-background-location-permission

Solution 9 - Android

Xamarin Forms Android:

//---------------------------------------------------------
public void OpenSettings()
//---------------------------------------------------------
{
    var intent = new Intent(Android.Provider.Settings.ActionApplicationDetailsSettings,
        Android.Net.Uri.Parse("package:" + Forms.Context.PackageName));
    Forms.Context.StartActivity(intent);
}

Solution 10 - Android

May be this will help you

private void openSettings() {
    Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
    Uri uri = Uri.fromParts("package", getPackageName(), null);
    intent.setData(uri);
    startActivityForResult(intent, 101);
}

Solution 11 - Android

If we are talking about Flyme (Meizu) only, it has its own security app with permissions.

To open it, use the following intent:

public static void openFlymeSecurityApp(Activity context) {
    Intent intent = new Intent("com.meizu.safe.security.SHOW_APPSEC");
    intent.addCategory(Intent.CATEGORY_DEFAULT);
    intent.putExtra("packageName", BuildConfig.APPLICATION_ID);
    try {
        context.startActivity(intent);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

Of course, BuildConfig is your app's BuildConfig.

Solution 12 - Android

It is not possible to pragmatically get the permission... but I’ll suggest you to put that line of code in try{} catch{} which make your app unfortunately stop...

And in the catch body, make a dialog box which will navigate the user to a small tutorial to enable the draw over other apps' permissions... then on the Yes button click add this code...

Intent callSettingIntent= new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION);
startActivity(callSettingIntent);

This intent is to directly open the list of draw over other apps to manage permissions and then from here it is one click to the draw over other apps' permissions.

I know this is not the answer you're looking for... but I’m doing this in my apps...

Solution 13 - Android

According to Android documentation

Try This

Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setComponent(new ComponentName(appDetails.packageName,"com.android.packageinstaller.permission.ui.ManagePermissionsActivity"));
startActivity(intent);

Solution 14 - Android

> Open the permission screen for a specific app

            if (ContextCompat.checkSelfPermission(
                    context, Manifest.permission.WRITE_EXTERNAL_STORAGE)
                != PackageManager.PERMISSION_GRANTED
            ) {
                //Permission is not granted yet. Ask for permission.
                val alertDialog = AlertDialog.Builder(context)
                alertDialog.setMessage(context.getString(R.string.file_permission))
                alertDialog.setPositiveButton("सेटिंग") { _, _ ->
                    val intent = Intent(
                        Settings.ACTION_APPLICATION_DETAILS_SETTINGS,
                        Uri.fromParts("package", BuildConfig.APPLICATION_ID, null)
                    )
                    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
                    context.startActivity(intent)
                }
                alertDialog.setNegativeButton("हाँ") { _, _ ->
                    ActivityCompat.requestPermissions(
                        context as Activity, arrayOf(
                            Manifest.permission.WRITE_EXTERNAL_STORAGE
                        ), 1
                    )
                }
                alertDialog.show()
            } else {}

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionFrederik SchweigerView Question on Stackoverflow
Solution 1 - AndroidMartin KonecnyView Answer on Stackoverflow
Solution 2 - AndroidThomas R.View Answer on Stackoverflow
Solution 3 - AndroidsinghpradeepView Answer on Stackoverflow
Solution 4 - AndroiddgngulcanView Answer on Stackoverflow
Solution 5 - AndroidUltimo_mView Answer on Stackoverflow
Solution 6 - AndroidSaiView Answer on Stackoverflow
Solution 7 - AndroidVignesView Answer on Stackoverflow
Solution 8 - AndroiddavidgyoungView Answer on Stackoverflow
Solution 9 - AndroidNick KovalskyView Answer on Stackoverflow
Solution 10 - AndroidSandeep KumarView Answer on Stackoverflow
Solution 11 - AndroidDanielView Answer on Stackoverflow
Solution 12 - AndroidAshishView Answer on Stackoverflow
Solution 13 - AndroidAshish ViraniView Answer on Stackoverflow
Solution 14 - AndroidAftab AlamView Answer on Stackoverflow