通过PackageManager开启任意应用
已知包名、启动Activity名:
Intent intent = new Intent();
String packageName = "org.zjphis.wsjd";
String clsName = packageName + ".LoginActivity";
ComponentName component = new ComponentName(packageName, clsName);
intent.setComponent(component);
startActivity(intent);
未知包名、启动Activity名,但知道应用名:
Intent mainIntent // 获取所有启动Activity的Intent
= new Intent(Intent.ACTION_MAIN, null);
mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
List<ResolveInfo> apps // 获取所有app信息
= getPackageManager().queryIntentActivities(mainIntent, 0);
if (apps != null) {
// 遍历信息列表
for (ResolveInfo resolveInfo : apps) {
Log.v(TAG, resolveInfo.toString());
String appName // 该应用名
= (String) resolveInfo.loadLabel(getPackageManager());
if ("浙江卫监".equals(appName)){
//该应用的包名
String pkg = resolveInfo.activityInfo.packageName;
//应用的主activity类
String cls = resolveInfo.activityInfo.name;
//打包应用信息
ComponentName componet = new ComponentName(pkg, cls);
Intent intent = new Intent();
intent.setComponent(componet);
startActivity(intent); // 开启