获取已安装的安卓应用程序列表
我想获得用户设备上所有已安装应用程序的列表,我一直在谷歌上搜索了最长时间,但找不到我想要的内容,但此链接是最近的,并且工作正常,除了我是新人'不明白如何使用方法 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
关于如何创建实际列表的任何帮助都将是一个主要帮助我已经拥有所有代码只是无法让列表实际显示对任何帮助的感谢
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) != 0) {
installedApps.add(app);
//it's a system app, not interested
} else if ((app.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
//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.