Jai*_*Jai 21 android android-package-managers
我想获取所有已安装应用的图标.我可以使用包管理器获取该图标吗?它有什么功能吗?或者以任何其他方式获取位图中所有已安装应用的图标?
谢谢!
Pon*_*lar 41
try {
String pkg = "com.app.my";//your package name
Drawable icon = getContext().getPackageManager().getApplicationIcon(pkg);
imageView.setImageDrawable(icon);
} catch (PackageManager.NameNotFoundException ne) {
}
Run Code Online (Sandbox Code Playgroud)
点击此处了解更多详情.
我知道我为时已晚。
以上答案都很好。
您的问题是:- 获取android中所有已安装应用的图标? 您想要安装应用程序列表图标
这是代码,可帮助您获取带有应用程序(图标,软件包名称)的安装应用程序列表。
**Declare variable in your Activity**
private CustomAppListAdapter customAppListAdapter;
private ArrayList<AppListMain> appListMainArrayList;
private AppListMain appListMain;
Run Code Online (Sandbox Code Playgroud)
只需在Activity onCreate()中调用下面的loadApps()函数即可
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_app_list);
loadApps();
}
public void loadApps() {
try {
packageManager = getPackageManager();
appListMainArrayList = new ArrayList<>();
Intent intent = new Intent(Intent.ACTION_MAIN, null);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
List<ResolveInfo> resolveInfoList = packageManager.queryIntentActivities(intent, 0);
for (ResolveInfo resolveInfo : resolveInfoList) {
AppListMain appListMain = new AppListMain();
appListMain.setAppIcon(resolveInfo.activityInfo.loadIcon(packageManager));
appListMain.setAppName(resolveInfo.loadLabel(packageManager).toString());
appListMain.setAppPackage(resolveInfo.activityInfo.packageName);
appListMainArrayList.add(appListMain);
}
} catch (Exception e) {
e.printStackTrace();
}
}
Run Code Online (Sandbox Code Playgroud)
这是参考链接
要么
您可以从My Github存储库下载自定义启动器代码
我发现这是最简单的方法:
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);
}
Run Code Online (Sandbox Code Playgroud)
现在要获取图标,请使用以下命令:
for(ResolveInfo ri : installedApps()) {
// to get drawable icon --> ri.loadIcon(package_manager)
}
Run Code Online (Sandbox Code Playgroud)