Получить предустановленное приложение и установить его пользователем - PullRequest
0 голосов
/ 06 июня 2018

Я хочу получить предустановленное приложение (например: - YouTube, Play store и т. Д.) И приложение, установленное при использовании.

Но я получаю и другие приложения, как показано на рис.как мне пропустить это приложение.

Поскольку YouTube также является системным приложением, а другое приложение также системным приложением.

Мне нужно такое приложение, как YouTube, телефон и хранилище сообщений, Naukari.com и т. д.

get other app also

Ответы [ 3 ]

0 голосов
/ 06 июня 2018

Попробуйте приведенный ниже код, и он работает нормально для меня.

В onCreate () вашей активности

new LoadApplications().execute();

Asynctask для получения всех системных приложений в Android

 private class LoadApplications extends AsyncTask<Void, Void, List<ApplicationInfo>> {

        @Override
        protected List<ApplicationInfo> doInBackground(Void... params) {
            systemAppsList = checkForLaunchIntent(packageManager.getInstalledApplications(PackageManager.GET_META_DATA));
            return systemAppsList;
        }

        @Override
        protected void onCancelled() {
            super.onCancelled();
        }

        @Override
        protected void onPostExecute(List<ApplicationInfo> result) {
            super.onPostExecute(result);
            setAdapter(result);
        }

        @Override
        protected void onPreExecute() {
            pProgressBar.setVisibility(View.VISIBLE);
            super.onPreExecute();
        }
    }


private List<ApplicationInfo> checkForLaunchIntent(List<ApplicationInfo> list) {

        ArrayList<ApplicationInfo> systemAppsList = new ArrayList<>();

        for (ApplicationInfo info : list) {
            try {
                if (null != packageManager.getLaunchIntentForPackage(info.packageName)) {

                    boolean isSystemApp = ((info.flags & ApplicationInfo.FLAG_SYSTEM) != 0);
                    Log.i("SystemApps", info.packageName + ", isSystemApp=" + isSystemApp);

                    if (isSystemApp) {
                        systemAppsList.add(info);
                    } 
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
         return systemAppsList;
    }


private void setAdapter(List<ApplicationInfo> result) {
        applicationAdapter = new ApplicationAdapter(getActivity(), systemAppsList);
        appListView.setAdapter(applicationAdapter);
    }
0 голосов
/ 06 июня 2018

Спасибо всем за помощь.Я получаю вывод, как мне нужно, с помощью следующего кода.

private List<AppList> getInstalledApps() {
    List<AppList> res = new ArrayList<AppList>();
    PackageManager pm = getActivity().getPackageManager();
    List<ApplicationInfo> apps = pm.getInstalledApplications(0);


    for (ApplicationInfo app : apps) {
        String appName = pm.getApplicationLabel(app).toString();
        String packageName = app.packageName;
        Drawable icon = pm.getApplicationIcon(app);

        if(!packageName.equals(BuildConfig.APPLICATION_ID)) {
            if (pm.getLaunchIntentForPackage(app.packageName) != null) {

                res.add(new AppList(appName, packageName, icon));

            }
        }
    }
    if(res.size()>0){
       Collections.sort(res, new Comparator<AppList>() {
           @Override
           public int compare(AppList o1, AppList o2) {
               return o1.getName().toLowerCase(Locale.getDefault()).compareTo(o2.getName().toLowerCase(Locale.getDefault()));

           }
       });
    }

    return res;
}
0 голосов
/ 06 июня 2018

Вы можете сделать так:

public static ArrayList<String> getAllVendorApp(Context context) {
        ArrayList<String> apps= new ArrayList<>();
        try {
            File[] systemFiles = new File("/system").listFiles();
            if (systemFiles != null) {
                for (File systemChild : systemFiles) {
                    if (systemChild.toString().contains("vendor") && systemChild.listFiles() != null) {
                        for (File vendorChild : systemChild.listFiles()) {
                            if (vendorChild.toString().contains("operator") && vendorChild.listFiles() != null) {
                                for (File operatorChild : vendorChild.listFiles()) {
                                    if (operatorChild.toString().contains("app") && operatorChild.listFiles() != null) {
                                        for (File operatorAppChild : operatorChild.listFiles()) {
                                            apps.add( operatorAppChild.toString().toLowerCase());

                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        } catch (Exception ex) {
            logException(ex);
        }
        return apps;
    }
...