I use the following code to get a list of all applications on my Android tablet and sort them alphabetically by name.
But for some reason it doesn't work - it leaves the list unchanged.
//load apps
final Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
final PackageManager pm = getActivity().getPackageManager();
final List<ResolveInfo> applist = pm.queryIntentActivities( mainIntent, 0);
//sort
Collections.sort(applist, new Comparator<ResolveInfo>(){
public int compare(ResolveInfo emp1, ResolveInfo emp2) {
return emp1.loadLabel(pm).toString().compareToIgnoreCase(emp2.loadLabel(pm).toString());
}
});
Fixed it by changing the applist's type from List to ArrayList