How to Get App's Permission for Each App? How to Do It Programmatically on Android

How to get App's Permission for each app? how to do it programmatically on Android?

You need to use PackageManager's GET_PERMISSIONS flag.

Check this question.

How to access permission screen of another app?

According to Android Docs, there is a class called PackageManager that can help you take a look at the Installed Packages on your phone.
In addition, it has the following method which should answer your question.

getPackageInfo(String packageName, int flags) :
Retrieves overall information about an application package that is installed on the system.

When combined with the flag PackageManager.GET_PERMISSIONS, you can retrieve the package's permissions.


Now regarding the actual changing of the Permissions for a certain application, I checked one of the applications that does what you asked about.

What the application has is its own accessibility service that turns off the permissions for you.

So, what happens is

  1. You are sent to the Permissions screen of a certain application, programmatically, through an intent and a package name.
Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
Uri uri = Uri.fromParts("package", packageName, null);
intent.setData(uri);
startActivity(intent);

  1. Then the accessibility service they have turns off the specified permission for you.
    It states that the accessibility service needs to Observe your actions which is probably used to know that the Permissions screen of a certain application opened. Then it uses Retrieve window content to be able to see which checkbox or toggle it needs to activate a press on and interact with.

You have to toggle the accessibility service from your settings, or it does not start. This is the only way I know of that you can do such a thing without root privileges.

Open App Permissions on Android programmatically?

Maybe you will be lucky and someone can prove me wrong, but it seems on recent version of Android you are limited to App Settings only - no direct access to App Permissions via Intent.

I believe this is related to Security and Automation which would also align with Googles decision to show an 'overlay detected' warning when trying to request permissions as outlined on this non-Google article

Go to My app's App Permission screen

No, there is no intent to go directly to the Permissions screen.

However, just as in previous versions of Android, you can point people to your application's detail setting page using code such as:

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

This will allow them to only hit a single button (the Permissions button on that screen) before they can access permissions.

Note that as per the UX around asking for permissions, consider linking to the settings page only as a last resort and only in cases where the permission is necessary for your app to function at all - ideally, you should show a strong rationale when shouldShowRequestPermissionRationale() returns true (i.e., they've denied it once but have not hit 'never ask again') such that the second time the user sees a permission dialog they know exactly why you need that permission. This means that users hitting 'never ask again' should be considered a very strong signal that the user will not ever grant you that permission.

How to open application permission window in app settings programmatically

This is not possible. You can open the App settings screen but not the permissions setting screen.

Refer to this question for more explanations.

Here I am sharing code to open application setting screen,

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

For more you can refer Open Application Settings Screen Android

How give the application manifest permissions? How to do it programmatically on Android?

  1. You can loop through all the app names and get their permissions and store them in a String Buffer like this:
    https://stackoverflow.com/a/14672557/10058326

  2. Or since you want permissions to be shown on button click, you can add for each app the code you have tried with the proper app name in a OnButtonClickListener

  3. Or you can extract the relevant permissions from the StringBuffer made earlier each time the button is clicked

EDIT: See these links on how to create a OnItemClickListener for the Recycler View. You can get the position of the row that was clicked and through that get the app name in that row which you can pass to another function. Then write code inside that function to get permissions for the app name passed and display it
https://antonioleiva.com/recyclerview-listener/

https://hackernoon.com/android-recyclerview-onitemclicklistener-getadapterposition-a-better-way-3c789baab4db

https://gist.github.com/riyazMuhammad/1c7b1f9fa3065aa5a46f

EDIT 2:
Instead of passing appNameAndPermissions to showDialog which contains the whole list, you need to extract permissions of a certain app from the String Buffer. Here's how:

     String app_name = itemView.findViewById(R.id.app_name_text_view).getText().toString();
int indexOfApp = appNameAndPermissions.indexOf(app_name);
int indexOfLastPermission = appNameAndPermissions.indexOf("\n", indexOfApp);
String permissions = appNameAndPermissions.substring(indexOfApp, indexOfLastPermission);


Related Topics



Leave a reply



Submit