瑞芯微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鸿蒙开发板,

相关推荐
Jomurphys9 分钟前
设计模式 - 适配器模式 Adapter Pattern
android
雨白13 分钟前
电子书阅读器:解析 EPUB 底层原理与实战
android·html
g***B73815 分钟前
Kotlin协程在Android中的使用
android·开发语言·kotlin
A***279527 分钟前
Kotlin反射机制
android·开发语言·kotlin
2501_9160074728 分钟前
iOS 应用性能测试的工程化流程,构建从指标采集到问题归因的多工具协同测试体系
android·ios·小程序·https·uni-app·iphone·webview
源码_V_saaskw30 分钟前
JAVA国际版同城跑腿源码快递代取帮买帮送同城服务源码支持Android+IOS+H5
android·java·ios·微信小程序
q***d1731 小时前
Kotlin在后台服务中的框架
android·开发语言·kotlin
我要添砖java1 小时前
<JAVAEE> 多线程4-wait和notify方法
android·java·java-ee
Mr_万能胶2 小时前
到底原研药,来瞧瞧 Google 官方《Android API 设计指南》
android·架构·android studio
BINGCHN2 小时前
NSSCTF每日一练 SWPUCTF2021 include--web
android·前端·android studio