/*
* 同时启动分屏两个软件
* */
private void launchDoubleApp() {
Intent intent = new Intent();
// com.xxx.xx 包名
// com.xxx.xx.xx.xxxxxxx 类名
intent.setComponent(new ComponentName("com.xxx.xx", "com.xxx.xx.ui.LauncherUI"));
intent.setFlags(Intent.FLAG_ACTIVITY_LAUNCH_ADJACENT | Intent.FLAG_ACTIVITY_NEW_TASK);
ActivityOptions activityOptions = ActivityOptions.makeBasic();
// activityOptions.setLaunchWindowingMode(3);
try {
Method method = ActivityOptions.class.getMethod("setLaunchWindowingMode", int.class);
// 这里分屏设置为 3,目前测试其他数字不能自动分屏
method.invoke(activityOptions, 3);
Log.i("dzy","start freeform activity window mode 5");
} catch (Exception e) {
e.printStackTrace();
}
Bundle bundle = activityOptions.toBundle();
startActivity(intent,bundle);
}
如果你要启动的是别人的应用,不知道包名和类名
先进入
adb shell
再运行下面命令,这条命令只能dump到你当前运行的App,当前所在类类名
dumpsys activity activities|grep Hist
图片.png
使用命令切换分屏顺序
进入adb shell
am start-activity --windowingMode 3 com.org.xxx.xxxxx/.MainActivity
am start-activity --windowingMode 4 com.org.xxx.xxxxx/.MainActivity
如果未出现上下交互,就退出后台应用,重新运行命令
上面这种操作,在重新开机后就会失效
下面这种操作在重启后仍可以(但测试过程中不稳定)
try {
Intent intent1 = new Intent();
intent1.setComponent(new ComponentName("com.org.xxx.xxx", "com.org.xxx.xxx.MainActivity"));
intent1.setFlags(Intent.FLAG_ACTIVITY_LAUNCH_ADJACENT | Intent.FLAG_ACTIVITY_NEW_TASK);
ActivityOptions activityOptions1 = ActivityOptions.makeBasic();
try {
Method method = ActivityOptions.class.getMethod("setLaunchWindowingMode", int.class);
method.invoke(activityOptions1, 3);
} catch (Exception e) {
e.printStackTrace();
}
startActivity(intent1,activityOptions1.toBundle());
Intent intent = new Intent();
intent.setComponent(new ComponentName("com.xxx.xx", "com.xxx.xx.ui.LauncherUI"));
// intent.setComponent(new ComponentName("com.xxx.xx", "com.xxx.xx.plugin.appbrand.ui.AppBrandUI"));
intent.setFlags(Intent.FLAG_ACTIVITY_LAUNCH_ADJACENT | Intent.FLAG_ACTIVITY_NEW_TASK);
ActivityOptions activityOptions = ActivityOptions.makeBasic();
// activityOptions.setLaunchWindowingMode(3);
try {
Method method = ActivityOptions.class.getMethod("setLaunchWindowingMode", int.class);
method.invoke(activityOptions, 4);
} catch (Exception e) {
e.printStackTrace();
}
startActivity(intent,activityOptions.toBundle());
} catch (Exception e) {
e.printStackTrace();
}
网友评论