开发者

getInstalledPackages issues in Android simulator / device 2.2

开发者 https://www.devze.com 2023-03-06 02:50 出处:网络
The code above does not give quite every installed package (for instance, it does not give the package this code is running f开发者_如何学Pythonrom). The code runs from the main thread, never tried ot

The code above does not give quite every installed package (for instance, it does not give the package this code is running f开发者_如何学Pythonrom). The code runs from the main thread, never tried other device / emulator versions besides device / emulator 2.2. Any idea what is wrong ?

Thanks

public Map<String, String> getInstalledPackages()
{
    Map<String, String> apps = new HashMap<String, String>();
    List<PackageInfo> appsInfo = pm.getInstalledPackages(0);

    for (PackageInfo appInfo: appsInfo)
    {
        try 
        {
            apps.put(appInfo.packageName, appInfo.versionName);

        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    return apps;
}

PS: if I try it with pm.getInstalledPackages(PackageManager.GET_ACTIVITIES) it returns an empty Map - tried on device ony


If I replace

List<PackageInfo> appsInfo = pm.getInstalledPackages(0);

with

List<PackageInfo> appsInfo = getPackageManager().getInstalledPackages(PackageManager.GET_ACTIVITIES);

I get the package of my application.

0

精彩评论

暂无评论...
验证码 换一张
取 消