得到包名称已安装的程序名称、程序

2023-09-12 05:58:27 作者:离落染纤尘一抹绕指柔

我已经试过了codeI粘贴下面..但是这给了我安装的每一个应用程序,但然后我需要检查每一个应用程序的是我或不带包名称...检查是否有code的地方,我可以通过包名到手机系统,以便它给了我所有已安装的应用程序基于该包的名字。

  PackageManager经理= getPackageManager();
        意图mainIntent =新的意图(Intent.ACTION_MAIN,NULL);
        mainIntent.addCategory(Intent.CATEGORY_DEFAULT);
        最后的名单,其中,ResolveInfo>应用程序= manager.queryIntentActivities(mainIntent,0);
        Collections.sort(应用程序,新的ResolveInfo.DisplayNameComparator(经理));
        ArrayList的<字符串> oArrInstalledHomeApps =新的ArrayList<字符串>();
        如果(应用程序!= NULL)
        {
            最终诠释计数= apps.size();

            的for(int i = 0; I<计数;我++)
            {
                ResolveInfo信息= apps.get(我);
                字符串strpackageName = info.activityInfo.applicationInfo.packageName;
如果(strpackageName.contains(com.ZZ.))
{
                oArrInstalledHomeApps.add(strpackageName);
}
            }
            返回oArrInstalledHomeApps;
        }
 

解决方案

即使世界一个干净的方式来做到这一点。

 最后PackageManager PM = getPackageManager();
        ArrayList的<字符串> oArrInstalledHomeApps =新的ArrayList<字符串>();
        //获取安装的应用程序列表。
        名单< ApplicationInfo>包= pm.getInstalledApplications(PackageManager.GET_META_DATA);
        对于(ApplicationInfo packageInfo:包)
        {
            Log.d(TAG,安装包:+ packageInfo.packageName);
            Log.d(TAG,启动活动:+ pm.getLaunchIntentForPackage(packageInfo.packageName));
            如果(packageInfo.packageName.contains(com.ZZ。))
            {
                oArrInstalledHomeApps.add(packageInfo.packageName);
            }
        }
        返回oArrInstalledHomeApps;
 

此link

安装程序提示文件文件名是无效的

i have tried the code i pasted below ..but that gives me every application installed but then i need to check each of the app is mine or not by checking with the package name...Is there a code to where i can pass the package name to the phone system so that it gives me all the apps installed based on that package name.

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;
        }

解决方案

Theres a cleaner way to do that.

 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;

Copied shamelessly from this link