Created
July 24, 2016 17:28
-
-
Save cinohub/4f6e92115151d06f54e9c732b424562a to your computer and use it in GitHub Desktop.
Get list installed app in android
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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