448

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

Is it possible to display the "App Permissions" screen for a specific app via an Intent or something similar?

Android M Permission Screen

It is possible to display the app's "App Info" screen in Settings with the following code:

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

Is there an analogous solution for directly opening the app's "App Permissions" screen?

I already did some research on this but I was not able to find a solution.

Adil Hussain
  • 30,049
  • 21
  • 112
  • 147
Frederik Schweiger
  • 8,472
  • 6
  • 25
  • 27
  • Try this it may be work http://stackoverflow.com/a/41221852/5488468 – Bipin Bharti Jan 03 '17 at 10:50
  • check this [Open Application Settings Screen Android](http://tips.androidgig.com/open-application-settings-screen-android/#.XNuKA4g1WK0.stackoverflow) – Ravi May 15 '19 at 03:40
  • Take a look https://stackoverflow.com/questions/47973175/no-activity-found-to-handle-intent-application-settings/71837394#71837394 – AllanRibas Apr 12 '22 at 06:04

15 Answers15

574

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);
Vlad
  • 7,997
  • 3
  • 56
  • 43
Martin Konecny
  • 57,827
  • 19
  • 139
  • 159
  • 34
    It is redirecting to general details of Application screen. How can go to specifically App Permissions screen. I don't want that remaining one click too, – Milind Mevada Apr 03 '17 at 06:17
  • 12
    @MilindMevada - you cannot do that at the moment. – Martin Konecny Apr 03 '17 at 15:28
  • 1
    could you send data from the settings activity to your activity using intents, in "realtime"? the issue im facing is handling this data in your activity **once** it got sent from the settings. – ThunderWiring Aug 29 '17 at 06:34
  • 1
    This works when debugging the app, but crashes with no real reason after signing the APK. Nothing obvious in the logcat either. – JCutting8 Jan 29 '19 at 12:03
207

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.


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.

Kotlin Version:

val intent = Intent(ACTION_APPLICATION_DETAILS_SETTINGS)
with(intent) {
   data = Uri.fromParts("package", requireContext().packageName, null)
   addCategory(CATEGORY_DEFAULT)
   addFlags(FLAG_ACTIVITY_NEW_TASK)
   addFlags(FLAG_ACTIVITY_NO_HISTORY)
   addFlags(FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS)
}

startActivity(intent)
double-beep
  • 5,031
  • 17
  • 33
  • 41
Thomas R.
  • 7,988
  • 3
  • 30
  • 39
  • I experienced the same and thought there might be a workaround / another solution for this... :-/ – Frederik Schweiger Sep 30 '15 at 17:01
  • Nope, unfortunately its not possible by design. For more information check out this discussion on Google+: https://goo.gl/Wqjjff – Frederik Schweiger Oct 15 '15 at 10:10
  • Is it possible to achieve if the user gave the app root-access ? If so, how? What about the global permissions screen? The one that lists all of the permissions, of all apps? – android developer Feb 09 '16 at 15:42
  • It definetley has to be possible because that is exactly what whatsapp is doing. if you install whatsapp on android 6.0 device at first start you get a dialog where you can open the permissions settings. – Mulgard Jun 15 '16 at 12:22
  • @Mulgard Just tried this and I get a dialog generated by Whatsapp asking whether it can ask you for permissions, followed by the native Android permission requests. No automtic opening of permission settings. – Rawling Jul 21 '16 at 07:21
  • 2
    @Mulgard Whatsapp must be using targetSdk="23". This allows the app to to prompt the user to enable the permission. If your target SDK < 23, being able to show the user the app permissions screen is useful, however seems like we can only show the general app settings screen. – vman Aug 24 '16 at 23:47
  • 6
    The Intent.FLAG_ACTIVITY_NO_HISTORY may sometimes cause a problemous situation on tablets when a pop-up is shown within the settings screen it will close the settings screen. Simply removing that flag will solve this issue. – Wirling Nov 15 '16 at 11:49
  • How to go one level lower? The user is redirected to Application Info in the Settings section, but they still have to press on the Permission section. That is a lot to ask of the user (they aren't technical nor reliable). How can I take them all the way to the Permission section? – portfoliobuilder Dec 27 '16 at 19:36
  • 1
    @Thomas R. What is the activity that you said must be started to do so but that was generating the security exception because of the missing permission that can't be declared? I'm curious about that. – Hugo Allexis Cardona Apr 23 '17 at 21:41
  • 2
    You can show a Toast at the same time instructing the user to go into "Permission" (good idea to localize this message even if rest of your app is not available in the language of the user) – vgergo May 07 '18 at 09:15
  • @vgergo How to get the localized version of a settings name ? (same string as the one used in the settings) Is it possible ? – toto_tata Aug 17 '19 at 17:15
116
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.

singhpradeep
  • 1,593
  • 1
  • 12
  • 11
44

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

Ultimo_m
  • 4,724
  • 4
  • 38
  • 60
  • nice use of Kotin extensions – David Jarvis Dec 20 '18 at 13:49
  • 1
    Here's a shorter version: `fun Context.openAppSystemSettings() = startActivity(Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS, Uri.fromParts("package", packageName, null)))` – copolii Sep 14 '22 at 17:29
  • you have leave a not that it is just app details settings but you have to tap on permissions button then anyway to open permissions screen – user924 Jan 13 '23 at 15:26
43

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)));
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
dgngulcan
  • 3,101
  • 1
  • 24
  • 26
  • 4
    You may want to use getActivity().getPackageName() to get the package name depending on how your build is configured. – Cory Roy Aug 17 '17 at 22:22
29

Kotlin style.

startActivity(Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS).apply {
    data = Uri.fromParts("package", packageName, null)
})
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Sai
  • 15,188
  • 20
  • 81
  • 121
21

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: Android 11 users can’t grant background location permission?

davidgyoung
  • 63,876
  • 14
  • 121
  • 204
18

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

Ramesh R
  • 7,009
  • 4
  • 25
  • 38
Vignes
  • 390
  • 4
  • 11
7

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);
}
Henk-Martijn
  • 2,024
  • 21
  • 25
Nick Kovalsky
  • 5,378
  • 2
  • 23
  • 50
6

In Kotlin

    /*
*
* To open app notification permission screen instead of setting
* */
fun Context.openAppNotificationSettings() {
    val intent = Intent().apply {
        when {
            Build.VERSION.SDK_INT >= Build.VERSION_CODES.O -> {
                action = Settings.ACTION_APP_NOTIFICATION_SETTINGS
                putExtra(Settings.EXTRA_APP_PACKAGE, packageName)
            }
            else -> {
                action = Settings.ACTION_APPLICATION_DETAILS_SETTINGS
                addCategory(Intent.CATEGORY_DEFAULT)
                data = Uri.parse("package:" + packageName)
            }
        }
    }
    startActivity(intent)
}

Above one is tested and working code, hope it will help.

Yogendra
  • 4,817
  • 1
  • 28
  • 21
5

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);
}
Sandeep Kumar
  • 69
  • 1
  • 10
  • An explanation would be in order. E.g., what is the idea/gist? Please respond by [editing (changing) your answer](https://stackoverflow.com/posts/51251354/edit), not here in comments (***without*** "Edit:", "Update:", or similar - the answer should appear as if it was written today). – Peter Mortensen Oct 06 '21 at 17:21
4

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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Daniel
  • 2,415
  • 3
  • 24
  • 34
0

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 {}
Aftab Alam
  • 1,969
  • 17
  • 17
-1

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...

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Ashish
  • 182
  • 2
  • 9
-1

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);
Phil Dukhov
  • 67,741
  • 15
  • 184
  • 220
Ashish Virani
  • 182
  • 1
  • 15
  • 1
    An explanation would be in order. E.g., what is the idea/gist? Please respond by [editing (changing) your answer](https://stackoverflow.com/posts/63615868/edit), not here in comments (***without*** "Edit:", "Update:", or similar - the answer should appear as if it was written today). – Peter Mortensen Oct 06 '21 at 17:23