Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
283 views
in Technique[技术] by (71.8m points)

android - How to get installed applications permissions

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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();
   }
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...