我试图通过提供应用程序名称来查找我的应用程序的包名称。以下方法在 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