您好我想所有的我一直在使用Google的时间最长的用户设备上安装的应用程序的列表,但无法找到我想要的这个链接是最接近的,但并工作正常,只是我是新唐'吨了解如何使用该方法getPackages();并创建一个列表,它
Hi I want to get a list of all of the installed applications on the users device I have been googling for the longest time but can't find what i want this link was the closest though and works fine except me being new don't understand how to use the method getPackages(); and create a list with it
http://www.androidsnippets.com/get-installed-applications-with-name-package-name-version-and-icon
如何创建实际的名单将是一个重要的帮助,我有所有code已经在就不能得到列表以实际显示任何帮助的感谢任何帮助
Any help on how to create the actual list would be a major help i have all that code already in just can't get the list to actually show thanks for any help
我在做这样的事情最近。有一件事我会说前面是要确保在一个单独的线程执行此 - 查询申请信息是缓慢的。下面将让你的所有已安装的应用程序列表。这将包括大量的系统应用程序,你可能不感兴趣的。
I was working on something like this recently. One thing I'll say up front is to be sure and perform this in a separate thread -- querying the application information is SLOW. The following will get you a list of ALL the installed applications. This will include a lot of system apps that you probably aren't interested in.
PackageManager pm = getPackageManager();
List<ApplicationInfo> apps = pm.getInstalledApplications(0);
要限制它只是在用户安装或更新系统中的应用程序(如地图,Gmail等),我用下面的逻辑:
To limit it to just the user-installed or updated system apps (e.g. Maps, GMail, etc), I used the following logic:
List<ApplicationInfo> installedApps = new ArrayList<ApplicationInfo>();
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);
}
}
编辑:另外,得到的名称和图标的应用程序(这可能是什么花费的时间最长 - 我没有做它任何真正的深度检测 - 使用:
Also, to get the name and icon for the app (which is probably what takes the longest -- I haven't done any real deep inspection on it -- use this:
String label = (String)pm.getApplicationLabel(app);
Drawable icon = pm.getApplicationIcon(app);
installedApps应该有你需要的应用程序的完整列表,现在。希望这会有所帮助,但你可能需要修改一些,具体取决于你需要已经返回哪些应用程序的逻辑。再次,它是缓慢的,但它只是你必须解决。你可能想建立一个数据缓存在一个数据库中,如果它的东西,你会被频繁访问。
installedApps should have a full list of the apps you need, now. Hope this helps, but you may have to modify the logic a bit depending on what apps you need to have returned. Again, it is SLOW, but it's just something you have to work around. You might want to build a data cache in a database if it's something you'll be accessing frequently.