2012-10-04 147 views

回答

1
final PackageManager pm = getPackageManager(); 
List<ApplicationInfo> packages = pm 
      .getInstalledApplications(PackageManager.GET_META_DATA); 
for (ApplicationInfo packageInfo : packages) { 
    Log.d(TAG, "Installed package : " + packageInfo.packageName); 
} 

然後你就可以檢查是否packageInfo.packageName等於它包含應用程序的包名稱一些字符串。

2

我檢查一下這種方式(檢查返回值不爲null):

public static Intent findFacebookClient(Context con) 
{ 
    final String[] FacebookApps = {"com.facebook.android", "com.facebook.katana"}; 
    Intent facebookIntent = new Intent(); 
    facebookIntent.setType("text/plain"); 
    final PackageManager packageManager = con.getPackageManager(); 
    List<ResolveInfo> list = packageManager.queryIntentActivities(facebookIntent, PackageManager.MATCH_DEFAULT_ONLY); 

    for (int i = 0; i < FacebookApps.length; i++) 
    { 
     for (ResolveInfo resolveInfo : list) 
     { 
      String p = resolveInfo.activityInfo.packageName; 
      if (p != null && p.startsWith(FacebookApps[i])) 
      { 
       facebookIntent.setPackage(p); 
       return facebookIntent; 
      } 
     } 
    } 
    return null; 
}