Programming HDMI output for dual screen

In my search, I found that the Android SDK does not support HDMI port management and HDMI output processing. Although some device manufacturers like Motorola (I don't know if anyone else can do this) provide an API for a little better control. Below are links to two of them, of which the dual screen (which suits my requirement pretty close) is out of date.

motorola hdmi status api

motorola hdmi dual screen api

Mirroring is the default behavior when connecting an HDMI, but I want my application to run a linked service on the HDMI output. This will allow the phone to perform any other tasks at the same time, without disrupting the operation of my service on the HDMI screen.

Can anyone suggest how I can do this? Or, if any other manufacturer provides the same flexibility as Motorola?

+5
source share
1 answer

Create such a service class.

public class MultiDisplayService extends Service {
    @Override
    public void onCreate() {
        super.onCreate();
        DisplayManager dm = (DisplayManager)getApplicationContext().getSystemService(DISPLAY_SERVICE);
        if (dm != null){
            Display dispArray[] = dm.getDisplays(DisplayManager.DISPLAY_CATEGORY_PRESENTATION);

        if (dispArray.length>0){
            Display display = dispArray[0];
            Log.e(TAG,"Service using display:"+display.getName());
            Context displayContext = getApplicationContext().createDisplayContext(display);
            WindowManager wm = (WindowManager)displayContext.getSystemService(WINDOW_SERVICE);
            View view = LayoutInflater.from(displayContext).inflate(R.layout.fragment_main,null);
            final WindowManager.LayoutParams params = new WindowManager.LayoutParams(
                    WindowManager.LayoutParams.FLAG_FULLSCREEN,
                    WindowManager.LayoutParams.FLAG_FULLSCREEN,
                    WindowManager.LayoutParams.TYPE_TOAST,
                    WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN,
                    PixelFormat.TRANSLUCENT);
            wm.addView(view, params);
        }
    }
}

Start the service, possibly in your Application class.

public class MultiDisplayApplication extends Application {
    @Override
    public void onCreate() {
        super.onCreate();
        startService(new Intent(this, MultiDisplayService.class));
    }
}

You will probably need more complex logic to add / remove display based DisplayManager.DisplayListener

mDisplayManager = (DisplayManager) this.getSystemService(Context.DISPLAY_SERVICE);
mDisplayManager.registerDisplayListener(this, null);

Use WindowManager.LayoutParams.TYPE_TOASTdoes not require any permissions, but it seems like a hack. WindowManager.LayoutParams.TYPE_SYSTEM_ALERTmay be more reasonable, but requieres

<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />

in your AndroidManifest.

+1
source

All Articles