我试图通过提供应用名称来查找我的应用程序的包名称。下面的方法在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
答案 0 :(得分:0)
您无需致电loadLabel()
查找包名称,只需直接从packageName
或ApplicationInfo
获取ResolveInfo
并进行比较。
使用loadLabel()
或loadIcon()
非常耗时。