客显与副屏

1. 双屏幕显示方案

双屏幕显示有两种方式:Android演示和RK DualScreen。 我们将专注于Android演示。 Android演示是Google提供的双屏幕解决方案,该解决方案在视图级别实现了VOP的分布。 该逻辑在同一应用程序上受到控制。

1.1 简介Android演示

演示文稿是由Android开发的,用于双屏幕显示。 可以在APK中实现它,通过给演示文稿单独的视图布局,以在主屏幕中实现相同的APK,并在子屏幕上显示不同的视图,以实现显着的结果。 它通过调用getDisplays的displayManagerService方法来获取第二个显示设备来起作用。 将第二个显示设备作为参数传递给演示文稿,然后在演示文稿中实现其UI内容,最后调用演示方法以在第二个显示设备上显示UI内容。

1.2 Introduction API

官方API和样本文档:

https://developer.android.com/reference/android/app/Presentation.html

Domestic documentation:

http://www.android-doc.com/reference/android/app/Presentation.html

Source code & demo:

Link Customer Display demo downloads

演示文稿是Google正式提供的特殊对话框类型,用于在其他非家庭屏幕显示器上显示特定内容。 创建时,它需要根据目标显示屏幕及其大小来绑定显示屏幕并配置上下文和资源。

1.3 Binding Display

  • Obtain and bind through the MediaRouter interface

1MediaRouter mediaRouter =(MediaRouter) context.getSystemService(Context.MEDIA_ROUTER_SERVICE);
2MediaRouter.RouteInfo route = mediaRouter.getSelectedRoute();
3if(route !=null){
4    Display presentationDisplay = route.getPresentationDisplay(); if(presentationDisplay !=null){
5           Presentation presentation =new MyPresentation(context, presentationDisplay); presentation.show();
  • Get and bind through the DisplayManager interface

 1DisplayManager displayManager =(DisplayManager) context.getSystemService(Context.DISPLAY_SERVICE);
 2Display[] presentationDisplays = displayManager.getDisplays(DisplayManager.DISPLAY_CATEGORY_PRESENTATION);
 3if(presentationDisplays.length >0){
 4    // If there is more than one suitable presentation display, then we could consider
 5    // giving the user a choice. For this example, we simply choose the first display
 6    // which is the one the system recommends as the preferred presentation display.
 7    Display display = presentationDisplays[0];
 8    Presentation presentation =new MyPresentation(context, presentationDisplay);
 9    presentation.show();
10            }

1.4 创建演示文稿

 1public class MyPresentation extends Presentation {
 2    /**
 3     * Rewrite constructor
 4     *
 5     * @param outerContext Context is not limited to Activity, it can also be Application Context or Service, etc.
 6     * @param display      Dislay of the secondary screen
 7     */
 8    public MyPresentation(Context outerContext, Display display) {
 9        super(outerContext, display);
10    }
11    @Override
12    protected void onCreate(Bundle savedInstanceState) {
13        super.onCreate(savedInstanceState);
14        setContentView(R.layout.xxx);
15        TextView textView = findViewById(R.id.text);
16    }
17}

1.5 设置辅助屏幕不会在主屏幕上退出

通常会创建演示文稿以在活动的背景下传递,并且将在创建的活动中显示或隐藏子屏幕,以创建一个全局子屏幕,该屏幕需要将系统弹出窗口特权添加到演示文稿中。 如前所述,如果必须添加系统弹出窗口权限,则可以是应用程序或服务的上下文,否则将崩溃,以便可以在任何地方新创建演示文稿。 * Add permissions to AndroidManifest.XML

1<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
  • Add code to Presentation

1getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);

备注

The system bullet window privileges of the Presentation will cover the ordinary Presentation, causing it unable to display; please dismiss the global Presentation before displaying the ordinary secondary screen, in order to make the switching smooth, the following code is recommended:

1.6 Android 8.0 API添加了新的窗口类型

Android 8.0 API为浮动窗口添加了一个窗口类型:TYPE_APPLICATION_OVERLAY

如果你的应用程序使用SYSTEM_ALERT_WINDOW权限,并试图使用以下窗口类型之一在其他应用程序和系统窗口上方显示提醒窗口:

1TYPE_PHONE
2TYPE_PRIORITY_PHONE
3TYPE_SYSTEM_ALERT
4TYPE_SYSTEM_OVERLAY
5TYPE_SYSTEM_ERROR
6TYPE_TOAST
_images/640.png

这些窗口将始终显示在使用TYPE_APPLICATION_OVERLAY窗口类型的窗口下面。

如果应用程序是8.0版本,应用程序只能使用TYPE_APPLICATION_OVERLAY窗口类型来创建浮动窗口。(其他窗口类型在8.0中已弃用。)

2. D1/Falcon 1双屏显示方案

2.1 Initialization of SDK calls

Source code & demo:

Link demo downloads

2.2 Binding Display