您的位置:首页 > 移动开发 > Android开发

Android 利用presentation实现双屏异显

2016-06-28 16:14 591 查看
我的思路是在主屏中开启activity,然后在副屏中开启服务,通过服务我们就可以让副屏一直显示或者播放节目或者打开其他应用,哪怕是退主屏退出activity。


// 获取显示设备。
public void updateContents() {
mDisplayManager = (DisplayManager) getSystemService(
Context.DISPLAY_SERVICE);
Display[] displays = mDisplayManager.getDisplays();
showPresentation(displays[1]);
}


// 将内容显示到display上面。
private void showPresentation(Display display) {
myPresentation = new MyPresentation(this, display);
myPresentation.setOnDismissListener(new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
// 监听消失,保存当前播放位置。
sharedPreferences.edit().putInt("index", nowHdmiPosition).commit();
sharedPreferences.edit().putInt("position", mBackgroundPlayer.getCurrentPosition()).commit();
}
});
myPresentation.getWindow().setType(WindowManager.LayoutParams.TYPE_PHONE);
myPresentation.show();
presentSurface = myPresentation.getSurface();
presentSurface.getHolder().addCallback(new MySurfaceCallback());
}


源码下载链接:

http://download.csdn.net/detail/bestchenq/9561946
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: