Hello Friends, We will see how to get list of all installed application from android device programmatically,
We call a method of PackageManager like
It returns a list of packageInfo object. Now we will strore our app list in ArrayList.
As shown below.
Now we have a list, we will just sort our array in alphabetical order using Java Collection API.
For that we require our custom comparator.
Create a Inner static class AlPhabeticalComarator
To store information of each application we require a Class Object Create as follows
Create a inner class as PInfo.
We call a method of PackageManager like
List<PackageInfo> packs = pm.getInstalledPackages(0);
As shown below.
/**** @param context* @param getSysPackages* @return List of installed application from the device*/private ArrayList<PInfo> getApps(Context context, boolean getSysPackages) {
final PackageManager pm = context.getPackageManager();ArrayList<PInfo> res = new ArrayList<PInfo>();List<PackageInfo> packs = pm.getInstalledPackages(0);
for (int i = 0; i < packs.size(); i++) {PackageInfo p = packs.get(i);if ((!getSysPackages) && (p.versionName == null)) {continue;}ApplicationInfo appinfo = p.applicationInfo;if(((appinfo.flags & ApplicationInfo.FLAG_SYSTEM) != (getSysPackages ? 1: ))))continue;if (pm.getLaunchIntentForPackage(p.packageName) == null) {continue;}PInfo info = new PInfo();info.appname= p.applicationInfo.loadLabel(pm).toString();info.pname = p.packageName;info.icon = p.applicationInfo.loadIcon(pm);res.add(newInfo);}Collections.sort(res, new AlPhabeticalComparator());return res;}
Now we have a list, we will just sort our array in alphabetical order using Java Collection API.
For that we require our custom comparator.
Create a Inner static class AlPhabeticalComarator
public static class AlPhabeticalComparator implements Comparator<PInfo> {@Overridepublic int compare(PInfo info1, PInfo info2) {return info1.appname.toUpperCase().compareTo(info2.appname.toUpperCase());}}
To store information of each application we require a Class Object Create as follows
Create a inner class as PInfo.
/**
* Static Inner class to hold application info
**/
public static class PInfo { public String appname = "";
public String pname = "";
public Drawable icon;
}
Thanks dude.. aweome, I was searching for :
ReplyDeletepublic static class AlPhabeticalComparator implements Comparator {
@Override
public int compare(PInfo info1, PInfo info2) {
return info1.appname.toUpperCase().compareTo(info2.appname.toUpperCase());
}
}
and the search ends here. :))
Thanks I get help using your code
ReplyDeleteCan you help me how we get app installed date & app size?
ReplyDeleteإذا كنت طالبًا في جامعة نجران، فقد تحتاج إلى خطة بحث تتناسب مع معايير الجامعة ومتطلباتها، تقدم لك إتقان للاستشارات الأكاديمية والتدريب خطة بحث جامعة نجران ، مع مراعاة أبعاد البحث المحلي والدولي، نحن نعمل على مساعدتك في تحديد أسلوب البحث المتوافق مع تطلعاتك الأكاديمية، مع استشاراتنا يمكنك تجهيز خطة بحث قوية تساعدك في التفوق الأكاديمي، اعتمد على فريقنا المحترف لضمان تقديم بحث يتماشى مع المتطلبات الأكاديمية الدقيقة
ReplyDelete