0
我想通過提供應用程序名稱來查找我的應用程序的包名稱。下面的方法在Droid3上花費很長時間。我如何優化這個或者我錯過了什麼?檢查設備上應用程序instaleld的列表並找到我的應用程序的軟件包名稱?
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
感謝您的回覆。在我的情況下,我有'應用程序名稱',並基於此,我需要找出這個應用程序是否已經安裝在設備上,如果是,然後提取'包名'。我如何用你的建議做到這一點? – codersnet 2012-08-15 17:51:02