在我的场景中,我想在我的应用程序中镜像另一个应用程序。
我用DisplayManager来表示createVirtualDisplay作为我的SurfaceView。然后,在启动活动时,我将DisplayId设置为AcitivityOptions中的这个VirtualDisplay。
通过这个过程,另一个应用程序可以在我的表面视图成功启动。但也有一些显示问题。根据我的测试,只有图像、背景颜色和GLSurfaceView.Renderer被正确渲染。ui组件(如TextView和Button )不会在SurfaceView中呈现。
从上面的测试结果,我想它可能与渲染的深度或顺序有关。
示例代码如下:
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,则MediaRouter或DisplayManager可以捕获这些活动。通过这种方式,一切都会正确显示(在我的测试中,我通过"Developer Options“->”模拟辅助显示“来模拟第二个监视器):
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());在虚拟显示模式中,是否有任何进程或配置错误的标志?谢谢你的帮助。
为了反映另一个应用程序,我已经扎根并推出了系统应用程序。
发布于 2022-01-21 15:36:50
您的问题是使用错误的createVirtualDisplay调用densityDpi,它应该是更大的数字,例如480,560。
https://stackoverflow.com/questions/59833788
复制相似问题