Is installed package can be move to SDCard

荒凉一梦 提交于 2019-12-12 17:11:52

问题


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?


回答1:


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


来源:https://stackoverflow.com/questions/10942749/is-installed-package-can-be-move-to-sdcard

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!