获取预安装的应用程序并由用户安装

时间:2018-06-06 05:15:21

标签: android installed-applications

我想要预先安装的应用程序(例如: - YouTube,Play商店等)和使用安装的应用程序。

但我正在获得其他应用程序,如图所示。我应该如何跳过这些应用程序。

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

我想要像YouTube,手机和信息存储,Naukari.com等应用

get other app also

3 个答案:

答案 0 :(得分: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;
}

答案 1 :(得分:0)

你可以这样做:

 - Namespace:  [default]
 - Kind:  Transactions
 - Key:  Transactions 
 - name: dummytranasction-id-string

答案 2 :(得分: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);
    }