Android如何查找第三方应用程序的资源标识符图标
我们可以找到第三方应用程序的资源标识符图标。实际上,我想用这些图标显示第三方应用程序 为了显示第三方应用程序,我使用listview。在适配器的getView方法中,我使用下面的代码Android如何查找第三方应用程序的资源标识符图标,android,Android,我们可以找到第三方应用程序的资源标识符图标。实际上,我想用这些图标显示第三方应用程序 为了显示第三方应用程序,我使用listview。在适配器的getView方法中,我使用下面的代码applicationInfo=pm.getApplicationInfo(appNames.get(position),pm.get\u META\u DATA); imageViewAppIcon.setImageDrawable(applicationInfo.loadIcon(pm)); 这会降低listv
applicationInfo=pm.getApplicationInfo(appNames.get(position),pm.get\u META\u DATA);
imageViewAppIcon.setImageDrawable(applicationInfo.loadIcon(pm));
这会降低listview的性能
如果我在ArrayList中保存drawable,它将保存大量可绘制(对象)列表。是否有帮助?通过这种方式,您可以检索手机上所有已安装应用的应用标签和图标:
PackageManager pm = getPackageManager();
Intent intent = new Intent(Intent.ACTION_MAIN, null);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
List<ResolveInfo> list = pm.queryIntentActivities(mainIntent, 0);
for (ResolveInfo resolveInfo : list) {
// Retrieve the current graphical icon associated with this resolution.
Drawable drawable = resolveInfo.loadIcon(pm);
// Retrieve the current textual label associated with this resolution.
CharSequence label = resolveInfo.loadLabel(pm);
}
Resources类中没有提供应用程序图标的资源ID的方法。只要您只想获取应用程序图标,就可以使用
ResolveInfo
。不需要应用图标资源ID。是否有人成功获得ID?Drawable可以工作,但资源ID有问题。
String packageName = "com.example.app";
Resources res = context.getPackageManager().getResourcesForApplication(packageName);