Android 利用presentation实现双屏异显

来源:互联网 发布:杭州软件外包公司 编辑:程序博客网 时间:2024/06/11 10:59
我的思路是在主屏中开启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

0 0
原创粉丝点击