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

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

 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();
}
}

应用在辅助显示器上显示不同的内容程序,以有线或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()回调方法。当新的显示器连接时,系统会调用这个回调方法。

 private final MediaRouter.SimpleCallback mMediaRouterCallback =
new MediaRouter.SimpleCallback() {
@Override
public void onRouteSelected(MediaRouter router, int type, RouteInfo info) {
Log.d(TAG, "onRouteSelected: type=" + type + ", info=" + info);
updatePresentation();
} @Override
public void onRouteUnselected(MediaRouter router, int type, RouteInfo info) {
Log.d(TAG, "onRouteUnselected: type=" + type + ", info=" + info);
updatePresentation();
} @Override
public void onRoutePresentationDisplayChanged(MediaRouter router, RouteInfo info) {
Log.d(TAG, "onRoutePresentationDisplayChanged: info=" + info);
updatePresentation();
}
};
 private void updatePresentation() {
// Get the current route and its presentation display.
MediaRouter.RouteInfo route = mMediaRouter.getSelectedRoute(
MediaRouter.ROUTE_TYPE_LIVE_VIDEO);
Display presentationDisplay = route != null ? route.getPresentationDisplay() : null; // Dismiss the current presentation if the display has changed.
if (mPresentation != null && mPresentation.getDisplay() != presentationDisplay) {
Log.i(TAG, "Dismissing presentation because the current route no longer "
+ "has a presentation display.");
mPresentation.dismiss();
mPresentation = null;
} // Show a new presentation if needed.
if (mPresentation == null && presentationDisplay != null) {
Log.i(TAG, "Showing presentation on display: " + presentationDisplay);
mPresentation = new DemoPresentation(this, presentationDisplay);
mPresentation.setOnDismissListener(mOnDismissListener);
try {
mPresentation.show();
} catch (WindowManager.InvalidDisplayException ex) {
Log.w(TAG, "Couldn't show presentation! Display was removed in "
+ "the meantime.", ex);
mPresentation = null;
}
} // Update the contents playing in this activity.
updateContents();
}
 private void updateContents() {
// Show either the content in the main activity or the content in the presentation
// along with some descriptive text about what is happening.
if (mPresentation != null) {
mInfoTextView.setText(getResources().getString(
R.string.presentation_with_media_router_now_playing_remotely,
mPresentation.getDisplay().getName()));
mSurfaceView.setVisibility(View.INVISIBLE);
mSurfaceView.onPause();
if (mPaused) {
mPresentation.getSurfaceView().onPause();
} else {
mPresentation.getSurfaceView().onResume();
}
} else {
mInfoTextView.setText(getResources().getString(
R.string.presentation_with_media_router_now_playing_locally,
getWindowManager().getDefaultDisplay().getName()));
mSurfaceView.setVisibility(View.VISIBLE);
if (mPaused) {
mSurfaceView.onPause();
} else {
mSurfaceView.onResume();
}
}
}

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

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

关于 Presentation api:http://android.toolib.net/reference/android/app/Presentation.html

android presentation的更多相关文章

  1. Android进阶笔记13:RoboBinding(实现了数据绑定 Presentation Model(MVVM) 模式的Android开源框架)

    1.RoboBinding RoboBinding是一个实现了数据绑定 Presentation Model(MVVM) 模式的Android开源框架.从简单的角度看,他移除了如addXXListen ...

  2. GJM : Unity3D HIAR -【 快速入门 】 五、导出 Android 工程、应用

    导出 Android 工程.应用 在开始之前,请务必先保存您的工程,同时确认您已经安装 Android SDK 和 JDK.安装操作请参考以下链接: 搭建开发环境 Step 1. 设置 Android ...

  3. Android MVP模式 谷歌官方代码解读

    Google官方MVP Sample代码解读 关于Android程序的构架, 当前(2016.10)最流行的模式即为MVP模式, Google官方提供了Sample代码来展示这种模式的用法. Repo ...

  4. Android Weekly Notes Issue #226

    Android Weekly Issue #226 October 9th, 2016 Android Weekly Issue #226 本期内容包括: 用Firebase做A/B Test; 用R ...

  5. Android应用架构之Android MVP使用

    前两篇已经将Retrofit和RxAndroid应用到了项目中,这篇本打算直接将Dagger2引进项目,但是考虑到整个项目结构,就来个结构整理吧,一起来看看网上炒得火热MVP模式. 说到MVP就不得不 ...

  6. 浅析 Android 的窗口

    来源:http://bugly.qq.com/bbs/forum.php?mod=viewthread&tid=555&fromuid=6   一.窗口的概念 在开发过程中,我们经常会 ...

  7. Xamarin.Android和UWP之MVVM的简单使用(二)

    0x01 前言 前面一篇,Xamarin.Android和UWP之MVVM的简单使用(一),主要讲了MvvmLight的简单使用 这篇主要讲讲MvvmCross的简单使用,例子的话,还是和上篇的一样. ...

  8. Xamarin.Android和UWP之MVVM的简单使用(一)

    0x01 前言 就目前而言,MVVM可以说是挺流行的,无论是web端还是移动端,web端的主要代表angularjs,avalonjs等, 移动端(xamarin,uwp)的代表应该是mvvmligh ...

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

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

随机推荐

  1. 数据结构和算法 – 7.散列和 Hashtable 类

    7.1.散列函数 散列是一种常见的存储数据的技术,按照这种方式可以非常迅速地插入和取回数据.散列所采用的数据结构被称为是散列表.尽管散列表提供了快速地插入.删除.以及取回数据的操作,但是诸如查找最大值 ...

  2. Delphi编程建议遵守的规范1---缩进、各种语句的用法

    在编程时候,尤其是在一个大的团队里面,遵守统一的编程规范是极其重要的.为所有的开发人员制定一个源代码书写标准,以及程序和文件的命名标准,使他们在编程时有一致的格式,这样,每个编程人员编写的代码能够被其 ...

  3. LIS的nlogn

    nlogn老忘,开个帖记录一下 开一个栈,每次取栈顶元素top和读到的元素temp做比较,如果temp > top 则将temp入栈:如果temp < top则二分查找栈中的比temp大的 ...

  4. 实时视频应用之QoS关键技术分析

    转自:http://www.aiweibang.com/m/detail/104476372.html?from=p 随着WebRTC标准的逐步推广,实时音视频通讯技术受到越来越多公司和技术人员的关注 ...

  5. 配置ogg异构oracle-mysql 双向同步注意事项

    双向同步需要考虑的是怎么解决循环复制,以及同时更新一张表以谁为基准. 配置过程就不写了,大致和oracle到mysql的单向+mysql到oracle的单向差不多. 需要注意的有如下几点: 1.ora ...

  6. 第十一篇:SOUI系统资源管理

    SOUI资源管理模块 从前篇已经讲到在SOUI中所有资源文件通过一个uires.idx文件进行索引. 这里将介绍在程序中如何引用这些资源文件. 在SOUI系统中,资源文件通过一个统一的接口对象读取: ...

  7. TCP, Scoket, HTTP

    1.TCP连接 要想明白Socket连接,先要明白TCP连接.手机能够使用联网功能是因为手机底层实现了TCP/IP协议,可以使手机终端通过无线网络建立TCP连接.TCP协议可以对上层网络提供接口,使上 ...

  8. 【spring bean】 spring中bean之间的引用以及内部bean

    在spring中会有如下的几种情况: 1.在当前容器中,(即在spring.xml这一个配置文件中),一个bean引用了另一个bean. 使用 1>  <ref  bean="另 ...

  9. Sublime text追踪函数插件:ctags 和php代码格式化

    转自:http://blog.csdn.net/zm2714/article/details/8076077 这两天一直纠结两款编辑器——eclipse和sublime Text. eclipse的p ...

  10. Loadrunner中参数化实战(7)-Unique+Each iteration

    参数化数据30条: 脚本如下,演示登录,投资,退出操作是,打印手机号: 首先验证Vugen中迭代: Unique+Each iteration 设置迭代4次Action 结果如下: