Determine list of permissions used by an installed application in Android

后端 未结 4 953
难免孤独
难免孤独 2020-12-09 06:42

I have to determine list of permission used each by the installed application on my device.

I have got the list of applications installed and there package name usin

4条回答
  •  青春惊慌失措
    2020-12-09 07:13

    Here how to retrieve the list of the apps installed on an Android device, and the permissions used by every app.

    private static final String TAG = "MyActivity";  
    ...
    
    final PackageManager pm = getPackageManager();
    final List installedApps = pm.getInstalledApplications(PackageManager.GET_META_DATA);
    
    for ( ApplicationInfo app : installedApps ) {
        //Details:
        Log.d(TAG, "Package: " + app.packageName);
        Log.d(TAG, "UID: " + app.uid);
        Log.d(TAG, "Directory: " + app.sourceDir);
    
        //Permissions:
        StringBuffer permissions = new StringBuffer();
    
        try {
            PackageInfo packageInfo = pm.getPackageInfo(app.packageName, PackageManager.GET_PERMISSIONS);
    
            String[] requestedPermissions = packageInfo.requestedPermissions;
            if ( requestedPermissions != null ) {
                for (int i = 0; i < requestedPermissions.length; i++) {
                    permissions.append(requestedPermissions[i] + "\n");
                }
    
                Log.d(TAG, "Permissions: " + permissions);
            }
        }
        catch ( PackageManager.NameNotFoundException e ) {
            e.printStackTrace();
        }
    }
    

提交回复
热议问题