0

我已经尝试了我在下面粘贴的代码..但这给了我安装的每个应用程序但是我需要通过检查包名称来检查每个应用程序是否是我的...是否有一个代码可以传递给我将包名称添加到电话系统,以便它为我提供基于该包名称安装的所有应用程序。

PackageManager manager = getPackageManager();
        Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
        mainIntent.addCategory(Intent.CATEGORY_DEFAULT);
        final List<ResolveInfo> apps = manager.queryIntentActivities(mainIntent, 0);
        Collections.sort(apps, new ResolveInfo.DisplayNameComparator(manager));
        ArrayList<String> oArrInstalledHomeApps = new ArrayList<String>();
        if (apps != null) 
        {
            final int count = apps.size();

            for (int i = 0; i < count; i++) 
            {
                ResolveInfo info = apps.get(i);
                String strpackageName = info.activityInfo.applicationInfo.packageName;
if(strpackageName.contains ("com.ZZ."))
{
                oArrInstalledHomeApps.add(strpackageName);
}
            }
            return oArrInstalledHomeApps;
        }
4

1 回答 1

2

有一种更清洁的方法可以做到这一点。

 final PackageManager pm = getPackageManager();
        ArrayList<String> oArrInstalledHomeApps = new ArrayList<String>();
        // get a list of installed apps.
        List<ApplicationInfo> packages = pm.getInstalledApplications(PackageManager.GET_META_DATA);
        for (ApplicationInfo packageInfo : packages)
        {
            Log.d(TAG, "Installed package :" + packageInfo.packageName);
            Log.d(TAG, "Launch Activity :" + pm.getLaunchIntentForPackage(packageInfo.packageName));
            if (packageInfo.packageName.contains("com.ZZ."))
            {
                oArrInstalledHomeApps.add(packageInfo.packageName);
            }
        }
        return oArrInstalledHomeApps;

从这个链接无耻地复制

于 2013-02-19T10:51:03.810 回答