在android中获取所有安装的应用程序的图标

我想获得我所有安装的应用程序的图标。 我可以使用包pipe理器获取图标吗? 有没有什么function呢? 或者任何其他方式来获取所有安装的应用程序的位图图标?

谢谢!

Related of "在android中获取所有安装的应用程序的图标"

try{ String pkg = "com.app.my";//your package name Drawable icon = getContext().getPackageManager().getApplicationIcon(pkg); imageView.setImageDrawable(icon); } catch (PackageManager.NameNotFoundException ne) { } 

在这里检查更多的细节。

试试这样做一个叫packageinformation的类:

  public class PackageInformation{ private Context mContext; public PackageInformation(Context context){ mContext=context; } class InfoObject { public String appname = ""; public String pname = ""; public String versionName = ""; public int versionCode = 0; public Drawable icon; public void InfoObjectAggregatePrint() {//not used yet Log.v(appname,appname + "\t" + pname + "\t" + versionName + "\t" + versionCode); } } private ArrayList<InfoObject> getPackages() { ArrayList<InfoObject> apps = getInstalledApps(false); final int max = apps.size(); for (int i=0; i<max; i++) { apps.get(i).prettyPrint(); } return apps; } public ArrayList<InfoObject> getInstalledApps(boolean getSysPackages) { ArrayList<InfoObject> res = new ArrayList<InfoObject>(); List<PackageInfo> packs = mContext.getPackageManager().getInstalledPackages(0); for(int i=0;i<packs.size();i++) { PackageInfo p = packs.get(i); if ((!getSysPackages) && (p.versionName == null)) { continue ; } InfoObject newInfo = new InfoObject(); newInfo.appname = p.applicationInfo.loadLabel(mContext.getPackageManager()).toString(); newInfo.pname = p.packageName; newInfo.versionName = p.versionName; newInfo.versionCode = p.versionCode; newInfo.icon = p.applicationInfo.loadIcon(mContext.getPackageManager()); res.add(newInfo); } return res; } } 

把它放在某个地方,现在可以从你的工作Activity类访问信息:

  PackageInformation androidPackagesInfo=new PackageInformation(this); ArrayList<InfoObject> appsData=androidPackagesInfo.getInstalledApps(true); for (InfoObject info : appsData) { Toast.makeText(MainActivity.this, info.appname,2).show(); Drawable somedrawable=info.icon; 

}

我觉得这是最简单的方法:

 private List<ResolveInfo> installedApps() { final Intent main_intent = new Intent(Intent.ACTION_MAIN, null); main_intent.addCategory(Intent.CATEGORY_LAUNCHER); return package_manager.queryIntentActivities(main_intent, 0); }