瑞芯微RK3576开发板Android14三屏异显开发教程

本文介绍瑞芯微RK3576平台Android14系统三屏异显开发的方法

演示设备:触觉智能EVB7608开发板

开发板接口:板载双千兆网口、HDMI2.1、Daul LVDS、HDMI IN、Type C(USB3.2)等。

异显实现原理

通过Presentation对象指定不同的DisplayID,来创建三个不同的窗口显示到三个显示屏上实现异显。

创建Presentation对象方法有三种:

1、直接指定DisplayID,创建Presentation对象;

2、通过MediaRouter获取Presentation对象;

3、通过DisplayManager获取Display对象→创建Presentation对象→调用Presentation的show函数;

代码实现

第一步:使用MediaRouter来获取当前选中的路由,并从中获取Display对象,然后创建并显示MyPresentation,代码如下:

复制代码
private void showSecondByMediaRouter(Context context) {    MediaRouter mediaRouter = (MediaRouter) context.getSystemService(Context.MEDIA_ROUTER_SERVICE);    MediaRouter.RouteInfo route = mediaRouter.getSelectedRoute(MediaRouter.ROUTE_TYPE_LIVE_VIDEO);    if (route != null) {        Display presentationDisplay = route.getPresentationDisplay();        if (presentationDisplay != null) {            presentation = new MyPresentation(context, presentationDisplay);            presentation.show();        }    }}

第二步:使用DisplayManager 来获取可用的显示器,并根据显示器的数量显示MyPresentation和MyPresentation2,代码如下:

复制代码
private void showSecondByDisplayManager(Context context) {    DisplayManager mDisplayManager = (DisplayManager) getSystemService(Context.DISPLAY_SERVICE);    Display[] displays = mDisplayManager.getDisplays(DisplayManager.DISPLAY_CATEGORY_PRESENTATION);    if (displays != null) {        if (displays.length >= 2) {            presentation = new MyPresentation(context, displays[0]);            presentation.show();            presentation2 = new MyPresentation2(context, displays[1]);            presentation2.show();        } else {            presentation = new MyPresentation(context, displays[displays.length - 1]);            presentation.show();        }    }}

第三步:使用 ActivityOptions来启动新的活动,并指定要在外部显示器上显示的内容,代码如下:

复制代码
private void showSecondByActivity(Context context) {    DisplayManager mDisplayManager = (DisplayManager) getSystemService(Context.DISPLAY_SERVICE);    Display[] displays = mDisplayManager.getDisplays(DisplayManager.DISPLAY_CATEGORY_PRESENTATION);    ActivityOptions options = ActivityOptions.makeBasic();    MediaRouter mediaRouter = (MediaRouter) context.getSystemService(Context.MEDIA_ROUTER_SERVICE);    MediaRouter.RouteInfo route = mediaRouter.getSelectedRoute(MediaRouter.ROUTE_TYPE_LIVE_VIDEO);    if (route != null) {        Display presentationDisplay = route.getPresentationDisplay();        options.setLaunchDisplayId(presentationDisplay.getDisplayId());        Intent intent = new Intent(MainActivity.this, MainActivity2.class);        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);        startActivity(intent, options.toBundle());    }    if (displays.length >= 2) {        ActivityOptions options2 = ActivityOptions.makeBasic();        options2.setLaunchDisplayId(2);        Intent intent = new Intent(MainActivity.this, MainActivity3.class);        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);        startActivity(intent, options2.toBundle());    }}

三异显测试测试

打开系统的触摸划线测试,运行修改为三显的DualScreenDemo APK,点击 Persentation DisplayManager来开启三个窗口分别显示在三个屏幕上。

从Dumpsys input中可以看到 两个ELAN Touchscreen分别对应上了 displayId 0、1和 2。分别在三个触摸屏上划线,对应的触摸屏分别在指定的屏幕上划线有效。

演示设备说明:

**触觉智能RK3576开发板,型号IDO-**EVB7608-V1

触觉智能RK3576鸿蒙开发板,

相关推荐
Carson带你学Android2 天前
Android PC时代已到来?Chrome OS将和Android合并!
android·google·chrome os
牛蛙点点申请出战2 天前
仿微信语音 WaveView -- Compose 实现
android·前端
没有了遇见3 天前
Android 基于JitPack Fork三方库代码 修改XPopup 资源ID异常BUG 并发布到仓库
android
sxczst3 天前
Launcher3 如何获取系统上的所有应用程序?
android
sxczst3 天前
如何在悬浮窗中使用 Compose?
android
XDMrWu3 天前
Compose 智能重组:编译器视角下的黑科技
android·kotlin
vivo高启强3 天前
R8 如何优化我们的代码(1) -- 减少类的加载
android·android studio
诺诺Okami3 天前
Android Framework-WMS-从setContentView开始
android
前行的小黑炭3 天前
Android :Compose如何监听生命周期?NavHostController和我们传统的Activity的任务栈有什么不同?
android·kotlin·app
Lei活在当下3 天前
【业务场景架构实战】5. 使用 Flow 模式传递状态过程中的思考点
android·架构·android jetpack