getInstalledPackages issues in Android simulator / device 2.2
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.
精彩评论