/**
* 获取已安装的应用的安装包
* @author Jason
*
*/
private class GetApksTask extends AsyncTask<Void, Void, List<App>> {
@Override
protected List<App> doInBackground(Void... params) {
List<App> apps = new ArrayList<App>();
PackageManager pm = getPackageManager();
List<ApplicationInfo> applicationInfos = pm.getInstalledApplications(PackageManager.GET_META_DATA);
for (ApplicationInfo applicationInfo : applicationInfos) {
if ((applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 0 && (applicationInfo.flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) == 0) {
App app = new App();
app.setAppIcon(((BitmapDrawable) applicationInfo.loadIcon(pm)).getBitmap());
app.setAppName(applicationInfo.loadLabel(pm).toString());
app.setAppPackageName(applicationInfo.packageName);
app.setPath(applicationInfo.publicSourceDir);
apps.add(app);
}
}
return apps;
}
@Override
protected void onPostExecute(List<App> apps) {
super.onPostExecute(apps);
appList.addAll(apps);
mAppAdapter.notifyDataSetChanged();
cancelProgress();
}
}