Good friends, I'm developing an app for the user to share, back up .. from third party apps. Get create a list where shows all the app's. It turns out that I do not want the system applications to appear, I want only those that have been installed by the user to appear.
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 will help me.