现在有一台Android设备,一个主屏和一个辅助显示器,现在客户需求让在辅助显示器上显示独特的内容,方案如下:
1)需要扩展Presentation类,并实现onCreate()回调方法,示例如下:
public class SecondScreen extends Presentation
{
public SecondScreen(Context paramContext, Display paramDisplay)
{
super(paramContext, paramDisplay);
}
protected void onCreate(Bundle paramBundle)
{
super.onCreate(paramBundle);
setContentView(R.layout.second);
}
}
2)获取辅助显示屏,控制其显示:
MediaRouter mMediaRouter = (MediaRouter)getSystemService(Context.MEDIA_ROUTER_SERVICE);
MediaRouter.RouteInfo route = mMediaRouter.getSelectedRoute(
MediaRouter.ROUTE_TYPE_LIVE_VIDEO);
Display presentationDisplay = route != null ? route.getPresentationDisplay() : null;
if (presentationDisplay != null) {
Presentation presentation = new SecondScreen(MainActivity.this, presentationDisplay);
presentation.show();
}