HDMI out programming for dual screen

一个人想着一个人 提交于 2019-12-21 15:24:12

问题


In my search I found that, the Android SDK provides no support for controlling HDMI port activities and handling HDMI output, as of now. Though certain device manufacturers like Motorola (don't know if any other does that too) provide API's for a little better control. Below are the links to two of them, out of which the dual screen one (which suits my requirement pretty close) is deprecated.

motorola hdmi status api

motorola hdmi dual screen api

Mirroring is the default behavior on connecting HDMI but, I want my app to run a binded service on HDMI out. This will allow the phone to perform any other tasks simultaneously, w/o disturbing my service running on the HDMI screen.

Can someone please suggest how can I go about it? Or if any other manufacturer provides similar flexibility as Motorola?


回答1:


Create a Service class like so.

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, perhaps 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 display add/remove logic based on DisplayManager.DisplayListener

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

Using WindowManager.LayoutParams.TYPE_TOAST requires no permissions but seems like a hack. WindowManager.LayoutParams.TYPE_SYSTEM_ALERT might be more reasonable, but requieres

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

in your AndroidManifest.



来源:https://stackoverflow.com/questions/10822097/hdmi-out-programming-for-dual-screen

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!