可能重复:
How do I check if an app is a non-system app in Android?
目前,此代码会返回所有内容,包括Android系统和时钟等系统应用。
public List<ApplicationInfo> getApps() {
final PackageManager pm = context.getPackageManager();
List<ApplicationInfo> packages = pm
.getInstalledApplications(PackageManager.GET_META_DATA);
return packages;
}
如何区分这些应用和用户安装的应用?
答案 0 :(得分:10)
您好,您可以使用以下代码
for(ApplicationInfo app : apps) {
//checks for flags; if flagged, check if updated system app
if((app.flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) == 1) {
installedApps.add(app);
//it's a system app, not interested
} else if ((app.flags & ApplicationInfo.FLAG_SYSTEM) == 1) {
//Discard this one
//in this case, it should be a user-installed app
} else {
installedApps.add(app);
}
}