[Android] Get installed APK List
Using PackageManager to get all application that uses’ installed and system native app.
Please import PackageManager and ResolveInfo first:
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
New an array-list to store app list:
private PackageManager mPm;
mPm = mContext.getPackageManager();
Intent mIntent = new Intent(Intent.ACTION_MAIN, null);
mIntent.addCategory(Intent.CATEGORY_LAUNCHER);
List<ResolveInfo> mResolveInfos = mPm.queryIntentActivities(mIntent, 0);
maybe we can get apps’ icon, packageName, className or other information
for (ResolveInfo rlf : mResolveInfos) {
try {
Log.d(TAG, rlf.activityInfo.packageName);
KeyInformation mInf = new KeyInformation();
ApplicationInfo app = mPm.getApplicationInfo(rlf.activityInfo.packageName, 0);
mInf.lable = mPm.getApplicationLabel(app).toString();
mInf.icon = mPm.getApplicationIcon(rlf.activityInfo.packageName);
mInf.packageName = rlf.activityInfo.packageName;
mInf.className = app.className;
mList.add(mInf);
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}
using adapter to draw a listview will be like this: