0

我试图通过提供应用程序名称来查找我的应用程序的包名称。以下方法在 Droid3 上花费了很长时间。我该如何优化这个或者我错过了什么?

 String                     sPackageName        = null;

   PackageManager           pm                  = m_Context.getPackageManager();

 //get a list of installed apps.
  List<ApplicationInfo>     packages            = pm.getInstalledApplications(PackageManager.GET_META_DATA);

  ApplicationInfo   ap  = new ApplicationInfo();
  ap.loadLabel(pm);



   for (ApplicationInfo packageInfo : packages) {

        String          sApp                = packageInfo.loadLabel( pm ).toString();

        //Log.d(TAG, "Installed AppName = " + appName + "  ,package :" + packageInfo.packageName );
        //Log.d(TAG,   "Launch Activity :" + pm.getLaunchIntentForPackage(packageInfo.packageName)); 

        if( sApp.compareTo( sAppName ) == 0 ){

            sPackageName    = packageInfo.packageName;
            break;
        }

   }// the getLaunchIntentForPackage  

   return sPackageName;

谢谢, DK

4

1 回答 1

0

您无需调用loadLabel()来查找包名称,只需packageName直接从ApplicationInfoor中获取ResolveInfo并进行比较即可。

使用loadLabel()orloadIcon()非常耗时。

于 2012-08-15T16:49:12.957 回答