Android判断应用是否存在_移动开发_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > 移动开发 > Android判断应用是否存在

Android判断应用是否存在

 2010/9/19 23:32:25    http://fonter.javaeye.com  我要评论(0)
  • 摘要:通过包名判断publicbooleancheckBrowser(StringpackageName){if(packageName==null||"".equals(packageName))returnfalse;try{ApplicationInfoinfo=getPackageManager().getApplicationInfo(packageName,PackageManager.GET_UNINSTALLED_PACKAGES);returntrue;}catch
  • 标签:Android判断应用

通过包名判断

 

 

	public boolean checkBrowser(String packageName) {
		if (packageName == null || "".equals(packageName))
			return false;
		try {
			ApplicationInfo info = getPackageManager().getApplicationInfo(
					packageName, PackageManager.GET_UNINSTALLED_PACKAGES);
			return true;
		} catch (NameNotFoundException e) {
			return false;
		}
	}

 

 

判断包中的Activity

 

 

		Intent intent = new Intent(Intent.ACTION_VIEW);
		intent.setClassName("com.android.settings", //$NON-NLS-1$
				"com.android.settings.InstalledAppDetails"); //$NON-NLS-1$
		intent.putExtra("com.android.settings.ApplicationPkgName", //$NON-NLS-1$
				mCurrentPkgName);
		List<ResolveInfo> acts = getPackageManager().queryIntentActivities(
				intent, 0);
		if (acts.size() > 0) {
			startActivity(intent);
		} else {
			Toast.makeText(this,
					getString(R.string.failed_to_resolve_activity),
					Toast.LENGTH_SHORT).show();
		}

 

发表评论
用户名: 匿名