安装包可以移动到SDCard

时间:2012-06-08 03:32:03

标签: java android debugging package sd-card

我得到了已安装软件包的列表,如何找到可以移动到SD卡的文件?

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

我既不能从当前找到.installLocation,也不能从PackageInfo中找到.INSTALL_LOCATION_INTERNAL_ONLY。问题是什么?


我既不能从当前找到.installLocation,也不能从PackageInfo中找到.INSTALL_LOCATION_INTERNAL_ONLY。问题是什么?

1 个答案:

答案 0 :(得分:4)

source code知道所有,

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
    }
}