Android双屏异显Presentation接口总结

    在点餐、收银、KTV等场所,对于双屏异显的需求是非常重要的,这样首先可以节省硬件成本。而现在的智能板卡很多运行Android系统,从Android4.2开始支持WiFi Display(Miracast)功能后,就开始支持双屏异显Presentation这套应用层接口了,下面以Android5.1系统来说明这套接口的使用要点:
    一个Presentation对象就是一个用于在第二显示设备上呈现内容的指定类型对话框,但这对话框是显示在第二屏,而普通的对话框是显示在主屏。
  那么,如何选择Presentation显示设备呢?下面是两种方法:
  1.使用media router
  使用MediaRoutergetPresentationDisplay()获取Presentation设备,Android源码目录下的development/samples/ApiDemos/src/com/example/android/apis/app/PresentationWithMediaRouterActivity.java文件有如下的代码段:
  MediaRouter mediaRouter = (MediaRouter) context.getSystemService(Context.MEDIA_ROUTER_SERVICE);
  MediaRouter.RouteInfo route = mediaRouter.getSelectedRoute();
  if (route != null) {
    Display presentationDisplay = route.getPresentationDisplay();
    if (presentationDisplay != null) {
      Presentation presentation = new MyPresentation(context, presentationDisplay);
      presentation.show();
    }
  }
  代码运行的效果如下截图:
  主屏:

  副屏(OpenGL动画):

  2.使用display manager
  使用DisplayManagergetDisplay(String)DISPLAY_CATEGORY_PRESENTATION类型来获得Presentation设备,Android源码目录下的development/samples/ApiDemos/src/com/example/android/apis/app/PresentationActivity.java有如下的代码段:
  DisplayManager displayManager = (DisplayManager) context.getSystemService(Context.DISPLAY_SERVICE);
  Display[] presentationDisplays = displayManager.getDisplays(DisplayManager.DISPLAY_CATEGORY_PRESENTATION);
  if (presentationDisplays.length > 0) {
    // If there is more than one suitable presentation display, then we could consider
    // giving the user a choice.  For this example, we simply choose the first display
    // which is the one the system recommends as the preferred presentation display.
    Display display = presentationDisplays[0];
    Presentation presentation = new MyPresentation(context, presentationDisplay);
    presentation.show();
  }
  代码运行的效果如下截图:
  主屏:

  副屏(随机图片):
  参考网址:
  http://android.toolib.net/reference/android/app/Presentation.html
  http://android.toolib.net/reference/android/media/MediaRouter.html#ROUTE_TYPE_LIVE_VIDEO
  http://android.toolib.net/reference/android/hardware/display/DisplayManager.html
  http://android.toolib.net/reference/android/view/Display.html
  http://challenges.s3.amazonaws.com/silicon_image/ExternalDisplay-1stEd.pdf

评论

此博客中的热门博文

I/O映射之I/O端口

通过Netlink检测网线插拔

使用seq_file