Get Icon from another android Application

给你一囗甜甜゛ 提交于 2019-12-20 19:22:08

问题


How do I get to the Icon Launcher from another Android application on the device if I know its Package Name?

Example

String googlePackageName = "com.google.maps";

Drawable googleIcon = googlePackageName.getIconLauncher() or something.

回答1:


Use PackagerManager's getApplicationIcon() for this task:

Drawable appIcon = getPackageManager().getApplicationIcon("com.google.maps");



回答2:


I came across this question. Never heard of before. But I guess this should be the solution:

Drawable icon = context.getPackageManager().getApplicationIcon(packageName);



回答3:


The following snipped should point you in the right direction:

final Intent intent = new Intent(Intent.ACTION_MAIN, null);
            intent.addCategory(Intent.CATEGORY_LAUNCHER);
            intent.setPackage( packageName );
            final List<ResolveInfo> pkgAppsList = pm.queryIntentActivities( intent, 0 );
            if( pkgAppsList.size() > 0 ) {
                this.url = pkgAppsList.get(0).activityInfo.name;
                icon = pkgAppsList.get(0).activityInfo.loadIcon( pm );
                this.displayName = pkgAppsList.get(0).activityInfo.loadLabel( pm ).toString();
                this.module = pkgAppsList.get(0).activityInfo.packageName;
                this.isExternal = true;
                this.count = count;
            }


来源:https://stackoverflow.com/questions/13609085/get-icon-from-another-android-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!