rec*_*nac 7 api user-interface android display android-virtualdisplay
在我的场景中,我想在我的应用程序中镜像另一个应用程序。
我DisplayManager用来createVirtualDisplay为我的SurfaceView. 然后我在开始活动时设置DisplayId为这个。VirtualDisplayAcitivityOptions
通过这个过程,另一个应用程序可以在我的表面视图中成功启动。但是有一些显示问题。根据我的测试,只有图像、背景颜色和GLSurfaceView.Renderer渲染正确。诸如TextView和 之类的 ui 组件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());
Run Code Online (Sandbox Code Playgroud)
相比之下,如果我将相同的活动镜像到一个Display而不是VirtualDisplay,则可以由MediaRouter或捕获DisplayManager。这样,一切都正确显示(在我的测试中,我通过“开发人员选项”->“模拟辅助显示器”模拟第二台显示器):
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());
Run Code Online (Sandbox Code Playgroud)
在虚拟显示模式下是否有我错过的任何进程或我错误配置的任何标志?谢谢你的帮助。
PS要镜像另一个应用程序,我已经植根并作为系统应用程序启动。
| 归档时间: |
|
| 查看次数: |
789 次 |
| 最近记录: |