首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在辅助虚拟显示器上启动时,活动显示不正确。

在辅助虚拟显示器上启动时,活动显示不正确。
EN

Stack Overflow用户
提问于 2020-01-21 03:25:42
回答 1查看 1.2K关注 0票数 8

在我的场景中,我想在我的应用程序中镜像另一个应用程序。

我用DisplayManager来表示createVirtualDisplay作为我的SurfaceView。然后,在启动活动时,我将DisplayId设置为AcitivityOptions中的这个VirtualDisplay

通过这个过程,另一个应用程序可以在我的表面视图成功启动。但也有一些显示问题。根据我的测试,只有图像、背景颜色和GLSurfaceView.Renderer被正确渲染。ui组件(如TextViewButton )不会在SurfaceView中呈现。

从上面的测试结果,我想它可能与渲染的深度或顺序有关。

示例代码如下:

代码语言:javascript
复制
SurfaceView surfaceView = findViewById(R.id.surface_view);
int flags = DisplayManager.VIRTUAL_DISPLAY_FLAG_PRESENTATION |
        DisplayManager.VIRTUAL_DISPLAY_FLAG_PUBLIC |
        DisplayManager.VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR;

DisplayManager displayManager = (DisplayManager) getSystemService(Context.DISPLAY_SERVICE);
VirtualDisplay virtualDisplay = displayManager.createVirtualDisplay("MyVirtualDisplay",
        surfaceView.getWidth(), surfaceView.getHeight(), 1, surfaceView.getHolder().getSurface(),
        flags);

int displayId = virtualDisplay.getDisplay().getDisplayId();
ActivityOptions options = ActivityOptions.makeBasic().setLaunchDisplayId(displayId);

Intent intent = getPackageManager().getLaunchIntentForPackage(appName);
    intent.addFlags(Intent.FLAG_ACTIVITY_LAUNCH_ADJACENT | Intent.FLAG_ACTIVITY_NEW_TASK);

startActivity(intent, options.toBundle());

相反,如果我将相同的活动镜像到Display而不是VirtualDisplay,则MediaRouterDisplayManager可以捕获这些活动。通过这种方式,一切都会正确显示(在我的测试中,我通过"Developer Options“->”模拟辅助显示“来模拟第二个监视器):

代码语言:javascript
复制
MediaRouter mediaRouter = (MediaRouter)getSystemService(Context.MEDIA_ROUTER_SERVICE);
MediaRouter.RouteInfo route = mediaRouter.getSelectedRoute(MediaRouter.ROUTE_TYPE_LIVE_VIDEO);
Display presentationDisplay = route.getPresentationDisplay();
int displayId = presentationDisplay.getDisplayId();

Intent intent = getPackageManager().getLaunchIntentForPackage(appName);
intent.addFlags(Intent.FLAG_ACTIVITY_LAUNCH_ADJACENT | Intent.FLAG_ACTIVITY_NEW_TASK);
ActivityOptions options = ActivityOptions.makeBasic().setLaunchDisplayId(displayId);

startActivity(intent, options.toBundle());

在虚拟显示模式中,是否有任何进程或配置错误的标志?谢谢你的帮助。

为了反映另一个应用程序,我已经扎根并推出了系统应用程序。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-01-21 15:36:50

您的问题是使用错误的createVirtualDisplay调用densityDpi,它应该是更大的数字,例如480,560。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59833788

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档