How to get installed applications permissions

2019-01-18 06:56发布

问题:

I need to develop an android application to detect malwares.

I am looking to develop this based on permissions used by all the applications installed. Please let me know how to identify the permissions used by other applications

回答1:

You can get all installed applications permissions like this.

  • Get all installed applications
  • Iterate over the applications
  • Get each application permissions list
  • Iterate over the each permission
PackageManager pm = getPackageManager();
List<ApplicationInfo> packages = pm.getInstalledApplications(PackageManager.GET_META_DATA);

for (ApplicationInfo applicationInfo : packages) {
   Log.d("test", "App: " + applicationInfo.name + " Package: " + applicationInfo.packageName);

   try {
      PackageInfo packageInfo = pm.getPackageInfo(applicationInfo.packageName, PackageManager.GET_PERMISSIONS);

      //Get Permissions
      String[] requestedPermissions = packageInfo.requestedPermissions;

      if(requestedPermissions != null) {
         for (int i = 0; i < requestedPermissions.length; i++) {
            Log.d("test", requestedPermissions[i]);
         }
      }
   } catch (NameNotFoundException e) {
      e.printStackTrace();
   }
}


回答2:

You can use this REST API to get details about an app, including permissions required by the app. For instance, to see what permissions WhatsApp is requiring, locate the "permissions" node in the response from this GET request: http://playstore-api.herokuapp.com/playstore/apps/com.whatsapp

More notes about how to make API calls for this could be found on the GitHub page.