Android get install location with packagename

2019-07-23 15:55发布

问题:

Hi i used the following code from this tutorial to list all of the installed applications in an app i'm working on.

http://impressive-artworx.de/2011/list-all-installed-apps-in-style/

I changed the onClick to my own dialog and what i now need to do is be able to get the location of the app. That is if it's in /system/app or /data/app i'd like to be able to toast the entire path to the pressed app but can't figure out how to do this. I can get the packagename by doing app.getPackageName() in the onClick but how can i get the apks path with this? Thank you for any suggestions or help it is much appreciated!

回答1:

After a bit more googling i got what i was looking for

PackageManager m = getPackageManager();
String s = getPackageName();
PackageInfo p = m.getPackageInfo(s, 0);
s = p.applicationInfo.sourceDir;

worked very well found it here

Get Application Directory

thanks for the help it helped with my googling as to what to look for



回答2:

Take a look at this . In particular the snippet with publicSourceDir .



回答3:

      List<PackageInfo> packs = packageManager.getInstalledPackages(0); //PackageManager.GET_META_DATA 
      for(int i=0; i < packs.size(); i++) {
         PackageInfo p = packs.get(i);
         ApplicationInfo a = p.applicationInfo; 
         // skip system apps if they shall not be included
         if ((!includeSysApps) && ((a.flags & ApplicationInfo.FLAG_SYSTEM) == 1)) {
            continue;
         }
         App app = new App();
         app.setTitle(p.applicationInfo.loadLabel(packageManager).toString());
         app.setPackageName(p.packageName);
         app.setVersionName(p.versionName);
         app.setVersionCode(p.versionCode);
         CharSequence description = p.applicationInfo.loadDescription(packageManager);
         app.setDescription(description != null ? description.toString() : "");
         apps.add(app);
      }

u can use this code to get the information of installed Applications.