How to get installed applications permissions

时光怂恿深爱的人放手 提交于 2019-12-17 18:57:20

问题


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.



来源:https://stackoverflow.com/questions/7937794/how-to-get-installed-applications-permissions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!