首页 > 移动平台 > 详细

启动其他app

时间:2014-03-20 18:31:41      阅读:542      评论:0      收藏:0      [点我收藏+]

在实际开发中,常有需求在程序启动第三方APP,直接上代码:

	private void openOtherAPP(Context context, String packageName) {
		PackageManager pm = context.getPackageManager();
		try {
			PackageInfo pi = pm.getPackageInfo(packageName, 0);
			if (pi != null) {
				Intent resolveIntent = new Intent(Intent.ACTION_MAIN, null);
				resolveIntent.addCategory(Intent.CATEGORY_LAUNCHER);
				resolveIntent.setPackage(pi.packageName);
				List<ResolveInfo> apps = pm.queryIntentActivities(resolveIntent, 0);
				ResolveInfo ri = apps.iterator().next();
				if (ri != null) {
					String pName = ri.activityInfo.packageName;
					String className = ri.activityInfo.name;
					Intent intent = new Intent(Intent.ACTION_MAIN);
					intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
					intent.addCategory(Intent.CATEGORY_LAUNCHER);
					ComponentName cn = new ComponentName(pName, className);
					intent.setComponent(cn);
					context.startActivity(intent);
				}
			}
		} catch (NameNotFoundException e) {
			e.printStackTrace();
		}
	}


 

启动其他app,布布扣,bubuko.com

启动其他app

原文:http://blog.csdn.net/u010142437/article/details/21623231

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!