4

I want to identify list of apps that are installed on phone memory & movable to sdcard. I am using following function to get list of installed apps.

I have checked Android Source code for InstalledAppDetails but unable to get solution.

Advance thanks

private List<App> loadInstalledApps(boolean includeSysApps) 
   {
       List<App> apps = new ArrayList<App>();

       //   the package manager contains the information about all installed apps
       PackageManager packageManager = getPackageManager();

       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);
           app.setInstallDir(p.applicationInfo.sourceDir);
           app.setInstallSize(calculateSize(app.getInstallDir()));
           CharSequence description = p.applicationInfo.loadDescription(packageManager);
           app.setDescription(description != null ? description.toString() : "");
           if(app.getInstallDir().contains("/mnt"))
           {
               //app on sdcard
               apps.add(app);
           }
           else
           {
               //app on phone memory
               apps.add(app);
           }        
       }
       return apps;
   }
Viren Ahir
  • 41
  • 2

1 Answers1

2

The App Install Location is specified on the AndroidManifest.xml of your app. Take a look here for more info. In short:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
android:installLocation="preferExternal"
... >

or

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
android:installLocation="auto"
... >

Where auto means that the app may be installed on external device but you don't have a preference; and preferExternal means that the app will be installed on external device when possible

Remember that...

If you do not declare this attribute, your application will be installed on the internal storage only and it cannot be moved to the external storage.

So, the question is now how to get the androidManifest.xml file from the app. Well, you can take it from the APK (if not deleted after installed). For that issue, take a look at this post: How to parse the AndroidManifest.xml file inside an .apk package

Finally, a great topic about parsing the xml is found on this post, too. Accessing android:installLocation manifest attribute

Cheers, Aldo

Community
  • 1
  • 1
aldo.roman.nurena
  • 1,323
  • 12
  • 26