1
Good friends, I’m developing an app for the user to share, back up .. from third-party apps. Be able to create a list where shows all the app’s. It turns out that I do not want to appear system applications, I want to appear only those that were installed by the user.
List<App> apps = new ArrayList<>();
/* Criar lista de aplicativos */
final PackageManager pm = getActivity().getPackageManager();
List<ApplicationInfo> packages = pm.getInstalledApplications(PackageManager.GET_META_DATA);
for (ApplicationInfo packageInfo : packages) {
String name;
/* Usar nome de pacote se o nome de etiqueta estiver vazio */
if ((name = String.valueOf(pm.getApplicationLabel(packageInfo))).isEmpty()) {
name = packageInfo.packageName;
}
Drawable icon = pm.getApplicationIcon(packageInfo);
String apkPath = packageInfo.sourceDir;
long apkSize = new File(packageInfo.sourceDir).length();
apps.add(new App(name, icon, apkPath, apkSize));
}
/* Organizar aplicativos na ordem alfabética */
Collections.sort(apps, new Comparator<App>() {
@Override
public int compare(App app1, App app2) {
return app1.getName().toLowerCase().compareTo(app2.getName().toLowerCase());
}
});
RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.app_list);
LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity());
new GridLayoutManager(getActivity(), 2);
recyclerView.setLayoutManager(layoutManager);
recyclerView.setHasFixedSize(true);
AppAdapter appAdapter = new AppAdapter(getActivity(), apps);
recyclerView.setAdapter(appAdapter);
return view;
}
}
Thank you very much, I hope you help me.