欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 教育 > 培训 > Android -- 双屏异显之方法二

Android -- 双屏异显之方法二

2025/5/17 5:49:36 来源:https://blog.csdn.net/weixin_43738911/article/details/144631012  浏览:    关键词:Android -- 双屏异显之方法二

Android – 双屏异显之方法二: DisplayManager

PS:
1. 使用改方法主板需连接至少两个输出显示屏;
2. 副屏内部实现与MediaRouter下一样;

使用方法

# 主屏activity内:
private SecondDisplay secondDisplay;private void dualScreen3288() {DisplayManager displayManager = (DisplayManager) getApplicationContext().getSystemService(DISPLAY_SERVICE);if (displayManager != null) {Display[] presentationDisplays = displayManager.getDisplays(DisplayManager.DISPLAY_CATEGORY_PRESENTATION);//检测到主屏外显示屏数if (presentationDisplays.length > 0) {// If there is more than one suitable presentation display, then we could consider giving the user a choice.  For this example, we simply choose the first display which is the one the system recommends as the preferred presentation display.//多个附加屏时可自由选择,这里选第一个secondDisplay = new SecondDisplay(this, presentationDisplays[0]);try {secondDisplay.show();} catch (Throwable e) {e.printStackTrace();}} else {logError("showDualScreen: 未找到副屏!");}}
}//关闭副屏
private void closeSecondScreen() {if (secondDisplay != null) {secondDisplay.release();secondDisplay.dismiss();secondDisplay = null;}
}

SecondDisplay.java (副屏类)

//主要继承Presentation类
public class SecondDisplay extends Presentation {private static final String TAG = "SecondDisplay";private Context mContext;//构造函数public SecondDisplay(Context outerContext, Display display) {super(outerContext, display);this.mContext = outerContext;}@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);//副屏布局,与activity内一样setContentView(R.layout.layout_second);initUI();}private void initUI() {//绑定控件}public void release() {//关闭页面前注销资源}
}

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词