2

我得到了已安装软件包的列表,我如何找出可以移动到 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);
                }
            }
        }
    }

我既无法从当前找到 .installLocation,也无法从 PackageInfo 中找到 .INSTALL_LOCATION_INTERNAL_ONLY。有什么问题?


我既无法从当前找到 .installLocation,也无法从 PackageInfo 中找到 .INSTALL_LOCATION_INTERNAL_ONLY。有什么问题?

4

1 回答 1

4

源代码什么都知道,

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
    }
}
于 2012-06-10T03:23:28.543 回答