Show only user-installed applications

1

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.

    
asked by anonymous 10.06.2016 / 00:45

1 answer

0

Try the following:

    final List<ApplicationInfo> mAllApp = context.getPackageManager().getInstalledApplications(PackageManager.GET_META_DATA);
    final List<ApplicationInfo> instalados = new ArrayList<>(0);

    for(final ApplicationInfo app : mAllApp){
        if((app.flags & ApplicationInfo.FLAG_SYSTEM) == 0) {
            // 1. Aplicativo baixado do Google Play Store
            instalados.add(app);
        }
    }

source

    
10.06.2016 / 13:47