2

I got a list of installed packages, how can I find out which one can be move to sdcard?

List<PackageInfo> list = pm.getInstalledPackages(0);
for (int i = 0; i < list.size(); i++) {

}

    if (_pm != null) {
        List<PackageInfo> list = _pm.getInstalledPackages(0);
        for (int i = 0; i < list.size(); i++) {
            PackageInfo current  = list.get(i);
            long pkgSize = new File(current.applicationInfo.sourceDir).length();
            String pkgName = current.packageName;
            String appName = current.applicationInfo.loadLabel(_pm).toString();
            Drawable appIcon = current.applicationInfo.loadIcon(_pm);

            //if (pInfo.installLocation != PackageInfo.INSTALL_LOCATION_INTERNAL_ONLY)//?

            PackageItem pi = new PackageItem(pkgName, pkgSize, appIcon, appName);

            if (_locationMode == LOCATION_PHONE) {
                if (!onSdCard(pkgName)) {
                    _adapter.add(pi);
                }
            } else {
                if (onSdCard(pkgName)) {
                    _adapter.add(pi);
                }
            }
        }
    }

I can neither find .installLocation from my current, nor find .INSTALL_LOCATION_INTERNAL_ONLY from PackageInfo. What 's the problem?


I can neither find .installLocation from my current, nor find .INSTALL_LOCATION_INTERNAL_ONLY from PackageInfo. What 's the problem?

Alex Lockwood
  • 83,063
  • 39
  • 206
  • 250
thecr0w
  • 2,148
  • 4
  • 33
  • 59
  • I think the problem is that you are using `0` instead of an actual, [constant flag](http://developer.android.com/reference/android/content/pm/PackageManager.html#GET_ACTIVITIES) (i.e. `PackageManager.GET_ACTIVITIES`). – Alex Lockwood Jun 12 '12 at 13:56
  • What do you mean? The problem is I can't find packaheInfo.installLocation in my eclipse. – thecr0w Jun 13 '12 at 02:25

1 Answers1

4

The source code knows all,

List<PackageInfo> list = pm.getInstalledPackages(PackageManager.GET_ACTIVITIES);

for (PackageInfo pInfo : list) {        
    if (pInfo.installLocation != PackageInfo.INSTALL_LOCATION_INTERNAL_ONLY) {
        // then it can be moved to the SD card
    } else {
        // otherwise, it can only be installed on internal storage
    }
}
Alex Lockwood
  • 83,063
  • 39
  • 206
  • 250
  • I can neither find .installLocation from my current, nor find .INSTALL_LOCATION_INTERNAL_ONLY from PackageInfo. What 's the problem? – thecr0w Jun 13 '12 at 04:31
  • 1
    Should parse location from manifest.xml. @see: http://stackoverflow.com/questions/3065219/accessing-androidinstalllocation-manifest-attribute – thecr0w Jun 14 '12 at 08:46