0

我正在开发一个应用程序,其中我从系统中获取已安装的应用程序。并成功显示在列表视图中。我成功地得到了每一件事。但现在它也让我得到了我不想要的系统应用程序。像这样的系统应用程序...浏览器,设置,闹钟这样我就不需要了。那么我该怎么做才能过滤呢?你能帮我解决这个...

代码 ::

private ArrayList<PInfo> getInstalledApps(boolean getSysPackages) {
        ArrayList<PInfo> res = new ArrayList<PInfo>();
        List<PackageInfo> packs = getPackageManager().getInstalledPackages(0);

        for (int i = 0; i < packs.size(); i++) {
            PackageInfo p = packs.get(i);
            // Fill PackageInfo
            if ((!getSysPackages) && (p.versionName == null)) {
                continue;
            }

            PInfo newInfo = new PInfo();
            newInfo.appname = p.applicationInfo.loadLabel(getPackageManager())
                    .toString();

            newInfo.pname = p.packageName;
            newInfo.versionName = p.versionName;
            newInfo.versionCode = p.versionCode;

            PackageManager pm = getPackageManager();

            ApplicationInfo appInfo;
            try {
                // Get all app information in Application info
                appInfo = pm.getApplicationInfo(newInfo.pname, 0);

                String appFile = appInfo.sourceDir;
                newInfo.size = String.valueOf(new File(appFile).length());

                long installed = new File(appFile).lastModified();
                newInfo.date = String.valueOf(installed);

                Date dtappdate = new Date(installed);
                newInfo.instdate = String.valueOf(dtappdate.toString());

            } catch (NameNotFoundException e) {
                e.printStackTrace();

            }catch (Exception e) {
                e.printStackTrace();
            }
            newInfo.icon = p.applicationInfo.loadIcon(getPackageManager());
            res.add(newInfo);
        }
        return res;
    }
4

1 回答 1

1

试试这个:

        PackageManager packageManager = getPackageManager();
        List<PackageInfo> packageList = packageManager.getInstalledPackages(0);
        for (PackageInfo pi : packageList) {
            ApplicationInfo ai = pi.applicationInfo;
            if ((ai.flags & ApplicationInfo.FLAG_SYSTEM) == 1){
                Log.d("APP_NAME", ai.loadLabel(packageManager).toString());
                Log.d("PACKAGE_NAME", pi.packageName);
                Log.d("APP_VERSION", pi.versionName);
            }
        }
于 2012-08-21T06:24:11.393 回答