Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get permission details programmatically

Is there anyway in android sdk where they provide an information for specific permission? Like how google play does, whenever you click on a permission you are able to read what does this permission do. I have this function to return me specific permissions for an application

public static List<String> getAppPermissions(Context context, String packageName) {
    try {
        PackageInfo info = context.getPackageManager().getPackageInfo(packageName, PackageManager.GET_PERMISSIONS);
        return Arrays.asList(info.requestedPermissions);
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
        return new ArrayList<>();
    }
} 

By this code im getting only permission names, but I'm wondering if there is any such api that return permissions and their details.

like image 854
Kosh Avatar asked Aug 22 '15 17:08

Kosh


People also ask

How do you check auto start permission is enabled or disabled programmatically?

There's no way to find out whether the Auto-start option is enabled or not. You can manually check under Security permissions => Autostart => Enable Autostart .

What is the use of shouldShowRequestPermissionRationale?

shouldShowRequestPermissionRationale. Gets whether you should show UI with rationale before requesting a permission. The target activity. A permission your app wants to request.

How can I programmatically open the permission screen for a specific app?

Is it possible to display the "App Permissions" screen for a specific app via an Intent or something similar? It is possible to display the app's "App Info" screen in Settings with the following code: startActivity( new Intent( android. provider.


1 Answers

to answer my question, PermissionInfo is actually the right class to get a description about any android permission for example:

@Nullable
public static PermissionInfo getPermissionInfo(@NonNull Context context, @NonNull String permission) {
    try {
        return context.getPackageManager().getPermissionInfo(permission, PackageManager.GET_META_DATA);
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
    }
    return null;
}

above method will return PermissionInfo instance if it could parse the permission name given to it, and then simply you could call loadDescription to load the permission description.

like image 94
Kosh Avatar answered Sep 20 '22 03:09

Kosh