-1

我想获得预安装的应用程序(如:- YouTube、Play 商店等)并通过使用安装应用程序。

但我也得到了其他应用程序,如图所示。我应该如何跳过这个应用程序。

因为 YouTube 也是系统应用程序,而其他应用程序也是系统应用程序。

我想要 YouTube、电话和消息存储、Naukari.com 等应用程序

还可以获取其他应用

4

3 回答 3

1

谢谢大家的帮助。我通过以下代码获得所需的输出。

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;
}
于 2018-06-06T07:56:15.510 回答
0

试试下面的代码,它对我来说很好用。

在您的活动的 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);
    }
于 2018-06-06T05:54:32.573 回答
0

你可以这样做:

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;
    }
于 2018-06-06T05:32:16.987 回答