2019独角兽企业重金招聘Python工程师标准>>>

对于双屏异显(lcd 和 hdmi 的双屏异显),android框架已经支持,但是底层接口功能还是要自己去实现,且需要底层驱动支持。

使用presentation 去画第二个display就好了。

1 MediaRouter mediaRouter = (MediaRouter) context.getSystemService(Context.MEDIA_ROUTER_SERVICE);
2 MediaRouter.RouteInfo route = mediaRouter.getSelectedRoute();
3 if(route != null) {
4      Display presentationDisplay = route.getPresentationDisplay();
5      if (presentationDisplay != null) {
6            Presentation presentation = new MyPresentation(context, presentationDisplay);
7            presentation.show();
8      }
9 }

应用在辅助显示器上显示不同的内容程序,以有线或Wi-Fi将外接显示输出连接到用户设备上,显示独特的内容。

注意:public Presentation (Context outerContext, Display display) 这个初始化函数,这里的outerContext必须要activity,一个activity的context,虽然presentation会创建自己的context,但是它是在这个参数context之上的,而且这个activity跳转后presentation就消失了,如果说用getApplicationContext()就直接报错,也不行。

要为辅助显示屏创建独特的内容:

1. 您需要扩展Presentation类,并实现onCreate()回调方法。在onCreate()中,调用setContentView()来指定您要在辅助显示屏上显示的UI。

2. 作为Dialog类的扩展,Presentation类提供了一个区域,在其中,您的应用可以在辅助显示屏上显示不同的UI。

获取显示Presentation的辅助显示屏:

1. 可以使用DisplayManager或者MediaRouter的API。其中,使用DisplayManagerAPI可以使您获得当前连接的所有显示屏的枚举,而MediaRouter则可以使您直接访问系统为Presentation设置的默认显示输出。

2. 可以给MediaRouter.getSelectedRoute()传一个ROUTE_TYPE_LIVE_VIDEO来获得演示的默认显示器。它将返回一个MediaRouter.RouteInfo对象,描述了系统为视频演示所选择的当前路由。如果MediaRouter.RouteInfo不空,调用getPresentationDisplay()即可获取当前连接的显示屏对象:Display。

3. 然后,您可以将这个Display对象传入Presentation的构造函数。调用Presentation.show()方法,演示就会出现在辅助显示屏上了。

为在运行时即时检测新接入的显示器,需要先创建一个MediaRouter.SimpleCallback的实例。在其中,您需要实现onRoutePresentationDisplayChanged()回调方法。当新的显示器连接时,系统会调用这个回调方法。

1 private final MediaRouter.SimpleCallback mMediaRouterCallback =2             new MediaRouter.SimpleCallback() {3         @Override4         public void onRouteSelected(MediaRouter router, int type, RouteInfo info) {5             Log.d(TAG, "onRouteSelected: type=" + type + ", info=" + info);6             updatePresentation();7         }8 9         @Override
10         public void onRouteUnselected(MediaRouter router, int type, RouteInfo info) {
11             Log.d(TAG, "onRouteUnselected: type=" + type + ", info=" + info);
12             updatePresentation();
13         }
14
15         @Override
16         public void onRoutePresentationDisplayChanged(MediaRouter router, RouteInfo info) {
17             Log.d(TAG, "onRoutePresentationDisplayChanged: info=" + info);
18             updatePresentation();
19         }
20     };
1 private void updatePresentation() {2         // Get the current route and its presentation display.3         MediaRouter.RouteInfo route = mMediaRouter.getSelectedRoute(4                 MediaRouter.ROUTE_TYPE_LIVE_VIDEO);5         Display presentationDisplay = route != null ? route.getPresentationDisplay() : null;6 7         // Dismiss the current presentation if the display has changed.8         if (mPresentation != null && mPresentation.getDisplay() != presentationDisplay) {9             Log.i(TAG, "Dismissing presentation because the current route no longer "
10                     + "has a presentation display.");
11             mPresentation.dismiss();
12             mPresentation = null;
13         }
14
15         // Show a new presentation if needed.
16         if (mPresentation == null && presentationDisplay != null) {
17             Log.i(TAG, "Showing presentation on display: " + presentationDisplay);
18             mPresentation = new DemoPresentation(this, presentationDisplay);
19             mPresentation.setOnDismissListener(mOnDismissListener);
20             try {
21                 mPresentation.show();
22             } catch (WindowManager.InvalidDisplayException ex) {
23                 Log.w(TAG, "Couldn't show presentation!  Display was removed in "
24                         + "the meantime.", ex);
25                 mPresentation = null;
26             }
27         }
28
29         // Update the contents playing in this activity.
30         updateContents();
31     }
1 private void updateContents() {2         // Show either the content in the main activity or the content in the presentation3         // along with some descriptive text about what is happening.4         if (mPresentation != null) {5             mInfoTextView.setText(getResources().getString(6                     R.string.presentation_with_media_router_now_playing_remotely,7                     mPresentation.getDisplay().getName()));8             mSurfaceView.setVisibility(View.INVISIBLE);9             mSurfaceView.onPause();
10             if (mPaused) {
11                 mPresentation.getSurfaceView().onPause();
12             } else {
13                 mPresentation.getSurfaceView().onResume();
14             }
15         } else {
16             mInfoTextView.setText(getResources().getString(
17                     R.string.presentation_with_media_router_now_playing_locally,
18                     getWindowManager().getDefaultDisplay().getName()));
19             mSurfaceView.setVisibility(View.VISIBLE);
20             if (mPaused) {
21                 mSurfaceView.onPause();
22             } else {
23                 mSurfaceView.onResume();
24             }
25         }
26     }

为针对辅助显示进一步优化Presentation的UI,您需要为您的应用或activity指定标签为android:presentationTheme主题。

请留意,连接到用户移动设备的屏幕往往有较大的屏幕尺寸和不同的屏幕密度。由于屏幕特征可能不同,您需要为大型显示设备提供特定优化的资源。如果您需要从Presentation中获取额外的资源,调用getContext().getResources()来获取针对这种显示的资源对象。这样,您的应用就可以根据辅助显示器的尺寸和密度提供最合适的资源了。

转载于:https://my.oschina.net/u/1389206/blog/893477

Android presentation相关推荐

  1. android studio 双屏,Android Presentation双屏异显,副屏的操作

    最近有一个双屏显示的需求,当时一脸蒙逼完全不知如何着手,不负众望找到解决办法,在Android4.2版本以后提供了Presentation类,可以轻松实现在两块屏幕上同时显示不同的内容.做一下笔记. ...

  2. Android | 说说Presentation

    目录 1.什么是Presentation 2.获取屏幕 2.1 使用media router来获取可以显示presentation的屏幕 2.2 通过Display Manager来获取present ...

  3. Android 双屏异显(Presentation) 开发,将第二个页面投屏到副屏上

    1. 背景 最近开发的一个项目,有两个屏幕,需要将第二个页面投屏到副屏上, 这就需要用到Android的双屏异显(Presentation)技术了,研究了一下,这里做下笔记. 我们那个副屏是一块汽车的 ...

  4. Android 双屏开发 Presentation 的使用教程

    使用Presentation 开发双屏 可以把Presentation 理解为一个特殊的Dialog 如果不知道Presentation 的使用,就简单的理解为类似自定义Dialog 下面来简单的演示 ...

  5. 【Android显示系统初探】多屏显示Presentation的使用

    Presentation通过指定displayID来决定显示在哪个屏幕上,这样就实现了多屏幕的显示(如果手机有多个显示设备), 也就让不同的屏幕可以显示不同的画面, 在只有一个显示设备的情况下,我们可 ...

  6. Android上成功实现了蓝牙的一些Profile

    前段时间做蓝牙方面的开发,Google的Android只实现了Handset/Handfree和A2DP/AVRCP等Profile,而其 它常用的Profile如HID/DUN/SPP/OPP/FT ...

  7. Android 应用程序集成Google 登录及二次封装

    谷歌登录API:  https://developers.google.com/identity/sign-in/android/ 1.注册并且登录google网站 https://accounts. ...

  8. 电子界卡组构建2019_2018–2019年构建现代Android应用程序的路线图

    电子界卡组构建2019 Kriptofolio应用程序系列-简介 (Kriptofolio app series - Introduction) Welcome to this series of b ...

  9. 关于android设备唯一区分device id的取得

    2019独角兽企业重金招聘Python工程师标准>>> 有些apk为了区分唯一设备,需要用到一个device id. 1. 取得设备的MAC address    如果用户没有通过w ...

最新文章

  1. 初学 Delphi 嵌入汇编[3] - 第一个 Delphi 与汇编的例子
  2. TCPDUMP中文手册
  3. ajax操作的链式写法
  4. android icon在线更新,Android在线更新下载方案
  5. android drawable转bitmap_Android 内存泄漏优化汇总
  6. 阿里云ACE认证之理解CDN技术
  7. 漏洞 立即留言_ASPCMS留言板漏洞注入一句话木马插入数据库及修复方法
  8. unity3d高版本转化低版本
  9. 即时通讯源码,IM源码-哇谷即时通讯源码,哇谷团队源码开发
  10. 计算机常用算法对照表整理
  11. 重订增广(清朝·周希陶)
  12. DarkGDK的杯具体验
  13. Pytorch - Tips
  14. 苹果三代耳机_【团品2】1.苹果原装数据线以及有线耳机 2.苹果蓝牙耳机
  15. 【STM32_hal库驱动NRF24L01】
  16. 红黑树解析(RB-Tree)
  17. Hive的nvl、coalesce、if、nvl2
  18. 顶点计划:996问题讨论
  19. SQL Assistant 12.x Crack
  20. 祝福你们,中国80后 (俞明洪)

热门文章

  1. ROS的学习(十四)用C++写一个简单的接收者
  2. Web前端开发工程师到底是干什么的?
  3. C语言和C++的区别到底是什么?
  4. ML————朴素贝叶斯原理和SKlearn相关库
  5. 用Golang写一个搜索引擎(0x07)--- 正排索引
  6. Google Guava之--cache
  7. 如何更有效地从阅读中汲取知识?
  8. 正则表达式之非捕获组
  9. 在IntelliJ IDEA中clone项目代码
  10. 程序员面试金典——3.4汉诺塔