Skip to content

Instantly share code, notes, and snippets.

@cinohub
Created July 24, 2016 17:28
Show Gist options
  • Save cinohub/4f6e92115151d06f54e9c732b424562a to your computer and use it in GitHub Desktop.
Save cinohub/4f6e92115151d06f54e9c732b424562a to your computer and use it in GitHub Desktop.
Get list installed app in android
private List<Application> getInstalledAppList() {
List<Application> listApps = new ArrayList<>();
final Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
final List pkgAppsList = getPackageManager().queryIntentActivities(mainIntent, 0);
ResolveInfoComparator resolveInfoComparator = new ResolveInfoComparator(getPackageManager());
Collections.sort(pkgAppsList, resolveInfoComparator);
String[] listPackageChecked = SharedPref.getInstance(getBaseContext()).getString(Constants.LIST_APP, "").split(getApplicationContext()
.getString(R.string.signal));
for (Object object : pkgAppsList) {
ResolveInfo info = (ResolveInfo) object;
Drawable icon = getBaseContext().getPackageManager().getApplicationIcon(info.activityInfo.applicationInfo);
String strPackageName = info.activityInfo.applicationInfo.packageName.toString();
final String title = (String) ((info != null) ? getBaseContext().getPackageManager().getApplicationLabel(info.activityInfo.applicationInfo) : "???");
Application app = new Application();
app.setmIcon(icon);
app.setmName(title);
app.setmPackage(strPackageName);
for (int i = 0; i < listPackageChecked.length; i++) {
if(strPackageName.equals(listPackageChecked[i])){
app.setChecked(true);
break;
}
}
listApps.add(app);
}
return listApps;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment