最安全方式
public static void startApp(Context context, String packageName) {
try {
PackageManager packageManager = context.getApplicationContext().getPackageManager();
Intent intent = packageManager.getLaunchIntentForPackage(packageName);
if (intent == null) {
LogUtils.d(packageName + ",应用不存在");
} else {
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.getApplicationContext().startActivity(intent);
}
} catch (Exception e) {
e.printStackTrace();
}
}
另外两种方式,如果第三方app做个参数校验,可能导致启动失败
Intent intent=new Intent();
//包名 包名+类名(全路径)
intent.setClassName("com.linxcool", "com.linxcool.PlaneActivity");
startActivity(intent);
Intent intent = new Intent();
ComponentName comp = new ComponentName("com.linxcool","com.linxcool.PlaneActivity");
intent.setComponent(comp);
intent.setAction("android.intent.action.MAIN");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);