我想确定安装在手机内存和可移动到 sdcard 上的应用程序列表。我正在使用以下功能来获取已安装应用程序的列表。
我已经检查了 InstalledAppDetails 的 Android 源代码,但无法获得解决方案。
提前谢谢
private List<App> loadInstalledApps(boolean includeSysApps)
{
List<App> apps = new ArrayList<App>();
// the package manager contains the information about all installed apps
PackageManager packageManager = getPackageManager();
List<PackageInfo> packs = packageManager.getInstalledPackages(0); //PackageManager.GET_META_DATA
for(int i = 0; i < packs.size(); i++)
{
PackageInfo p = packs.get(i);
ApplicationInfo a = p.applicationInfo;
// skip system apps if they shall not be included
if ((!includeSysApps) && ((a.flags & ApplicationInfo.FLAG_SYSTEM) == 1))
{
continue;
}
App app = new App();
app.setTitle(p.applicationInfo.loadLabel(packageManager).toString());
app.setPackageName(p.packageName);
app.setVersionName(p.versionName);
app.setVersionCode(p.versionCode);
app.setInstallDir(p.applicationInfo.sourceDir);
app.setInstallSize(calculateSize(app.getInstallDir()));
CharSequence description = p.applicationInfo.loadDescription(packageManager);
app.setDescription(description != null ? description.toString() : "");
if(app.getInstallDir().contains("/mnt"))
{
//app on sdcard
apps.add(app);
}
else
{
//app on phone memory
apps.add(app);
}
}
return apps;
}