HDMI输出编程双屏 [英] HDMI out programming for dual screen

查看:2600
本文介绍了HDMI输出编程双屏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的搜索,我发现,Android SDK中提供了用于控制HDMI端口的活动和处理HDMI输出,截至目前没有支持。虽然某些设备制造商如摩托罗拉(不知道是否有其他确实太)提供API的一点点更好的控制。下面是其中的两个,其中的双屏幕一(这符合我的要求pretty的接近)是德precated的链接。

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.

摩托罗拉HDMI状态API

摩托罗拉HDMI双屏API

镜像是在连接HDMI的默认行为,但是,我想我的应用程序运行在HDMI一个绑定的服务了。这将允许手机能够同时执行其他任务,W / O打扰我的服务的HDMI屏幕上运行。

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?

推荐答案

创建服务类,如下所示。

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));
    }
}

您可能需要根据 DisplayManager.DisplayListener

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

使用 WindowManager.LayoutParams.TYPE_TOAST 要求没有权限,但似乎是一个黑客。 WindowManager.LayoutParams.TYPE_SYSTEM_ALERT 可能是比较合理的,但requieres

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" />

在你的Andr​​oidManifest。

in your AndroidManifest.

这篇关于HDMI输出编程双屏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆