Search code examples
javaandroidandroid-intentandroid-permissionsandroid-settings

Android Settings permissions not not acting as they should


I need to ask for permission from the user. One of the permissions I need is ACTION_MANAGE_OVERLAY_PERMISSION and the other is Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION. When asking for it as you can see in the code below, it takes the user to the Settings screen so the user could tick the permission from there.

Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION,
        Uri.parse("package:" + getPackageName()));
startActivityForResult(intent, OVERLAY_PERMISSION_REQUEST_CODE);

On some Android phones and Android versions, it takes the user straight to the specific application setting (the app that it is called from) on other devices it opens up the list of applications from which the user has to find the app and then tick the permission. In most cases on Androids lower than 10 it opens up the specific app settings window and when it's 10 or higher, it opens up the list.
Is there a way to make it consistently open the current application setting that is open?

I tried adding:

intent.addCategory("android.intent.category.DEFAULT");
intent.setData(Uri.parse("package:" + getApplicationContext().getPackageName()));

But that did not help either.

And secondly, is there a way to ask for this and other Settings permissions without opening the Settings menu and instead of doing it in a dialog inside the application?
If not then is there a way to ask for multiple Settings permissions one after another because my application requires two Settings type permissions.

EDIT

Here is what I meant by the specific application settings vs the list.

All application listSpecific app

On the left picture, all apps are listed and on the right picture the specific app is opened (happens if you click on the app in the list).

Now in some cases, it directly opens the right picture but mostly it opens the left. Is there a way to force open the right picture at all times?


Solution

  • Is there a way to force open the right picture at all times?

    No.

    The Settings app usually is modified substantially by the device manufacturer. They can do whatever they want. This includes ignoring the Uri or outright removing third-party access to this screen, where the latter is what the documentation is warning against:

    In some cases, a matching Activity may not exist, so ensure you safeguard against this.

    If you make your own Android firmware, you could ensure that this Intent action behaves as you want, for whatever devices run your firmware.