android启动多个第三方app吗,【Android】启动第三方App的方法

  • Post author:
  • Post category:其他


方法一

private voiddoStartApplicationWithPackageName(String packagename) {

//通过包名获取此APP详细信息,包括Activities、services、versioncode、name等等

PackageInfo packageinfo =null;

try{

packageinfo = getPackageManager().getPackageInfo(packagename,0);

}catch(PackageManager.NameNotFoundException e) {

e.printStackTrace();

}

if(packageinfo ==null) {

return;

}

//创建一个类别为CATEGORY_LAUNCHER的该包名的Intent

Intent resolveIntent =newIntent(Intent.ACTION_MAIN, null);

resolveIntent.addCategory(Intent.CATEGORY_LAUNCHER);

resolveIntent.setPackage(packageinfo.packageName);

//通过getPackageManager()的queryIntentActivities方法遍历

List resolveinfoList = getPackageManager()

.queryIntentActivities(resolveIntent,0);

ResolveInfo resolveinfo = resolveinfoList.iterator().next();

if(resolveinfo !=null) {

// packagename =参数packname

String packageName = resolveinfo.activityInfo.packageName;

//这个就是我们要找的该APP的LAUNCHER的Activity[组织形式:packagename.mainActivityname]

String className = resolveinfo.activityInfo.name;

// LAUNCHER Intent

Intent intent =newIntent(Intent.ACTION_MAIN);

intent.addCategory(Intent.CATEGORY_LAUNCHER);

//设置ComponentName参数1:packagename参数2:MainActivity路径

ComponentName cn =newComponentName(packageName,className);

intent.setComponent(cn);

startActivity(intent);

}

}

方法二

直接通过Intent获取指定包名启动App

// 通过包名获取要跳转的app,创建intent对象

Intent intent = getPackageManager().getLaunchIntentForPackage(“com.tencent.mobileqq”);

// 这里如果intent为空,就说名没有安装要跳转的应用嘛

if (intent != null) {

startActivity(intent);

} else {

// 没有安装要跳转的app应用,提醒一下

}

其他将来补充……