Using this code:
final PackageManager pm = getActivity().getPackageManager();
//get a list of installed apps.
List<ApplicationInfo> packages = pm.getInstalledApplications(PackageManager.GET_META_DATA);
for (ApplicationInfo packageInfo : packages) {
Log.d(TAG, "Installed package :" + packageInfo.packageName);
Log.d(TAG, "Launch Activity :" + pm.getLaunchIntentForPackage(packageInfo.packageName));
I can display in the logcat package infos etc.. But i want display a list in my activity of installed apps with its icon if possible and the name of application. Is it possible? ps: i'm using fragments
观看此演示: Circle启动器
Following should do the job of getting the list of applications
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
applications = mPackageManage.queryIntentActivities(intent, PackageManager.GET_META_DATA);
Try like this,
First create a model for PackageItem
public class PackageItem {
private Drawable icon;
private String name;
private String packageName;
public String getPackageName() {
return packageName;
}
public void setPackageName(String packageName) {
this.packageName = packageName;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Drawable getIcon() {
return icon;
}
public void setIcon(Drawable icon) {
this.icon = icon;
}
}
Step 2)
This will give you list of all install application with Application Name,Icon and Package also
public List<PackageItem> getInstalledApplication(){
PackageManager appInfo = getPackageManager();
List<ApplicationInfo> listInfo = appInfo.getInstalledApplications(0);
Collections.sort(listInfo, new ApplicationInfo.DisplayNameComparator(appInfo));
List<PackageItem> data = new ArrayList<PackageItem>();
for (int index = 0; index < listInfo.size(); index++) {
try {
ApplicationInfo content = listInfo.get(index);
if ((content.flags != ApplicationInfo.FLAG_SYSTEM) && content.enabled) {
if (content.icon != 0) {
PackageItem item = new PackageItem();
item.setName(getPackageManager().getApplicationLabel(content).toString());
item.setPackageName(content.packageName);
item.setIcon(getPackageManager().getDrawable(content.packageName, content.icon, content));
data.add(item);
}
}
} catch (Exception e) {
}
}
return data;
}
Now You can use this List in your adapter class,
Hope this will help you.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.