软糖外接显示器与MediaRouter或DISPLAYMANAGER发现 [英] JellyBean external display not found with MediaRouter or DisplayManager

查看:723
本文介绍了软糖外接显示器与MediaRouter或DISPLAYMANAGER发现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用presenter功能豆形软糖中显示更多的大屏幕上自定义图形。 ( - > HDMI的microUSB)我与MHL HDMI兼容适配器连接。我的code试图探测外接显示器这块如下。出于某种原因 - 我得到我的外部显示器上输出,但DISPLAYMANAGER不会检测外接显示器。我不知道这是否与适配器做或者如果我连手机外接显示器与HDMI电缆将是如此直接?

我的logcat: http://postimg.org/image/sloflge1b/

我的code片:

  @燮pressLint(NewApi)
私人无效更新presentation(){
    //获取当前路由和presentation显示。
    Log.d(EXTRA_DISPLAY_TAG,内部更新presentation()调用......);    MediaRouter.RouteInfo路线= mediaRouter.getSelectedRoute(MediaRouter.ROUTE_TYPE_LIVE_VIDEO);    Log.d(EXTRA_DISPLAY_TAG,路线名称:+ route.getName()+,路由状态:+ route.getStatus());
    显示externalDisplay = NULL;
    如果(路线= NULL&放大器;!&安培; route.getName()等于(HDMI)){
        externalDisplay = route.get presentationDisplay();
        如果(externalDisplay == NULL){//也许没有准备好......
            Log.d(EXTRA_DISPLAY_TAG,等待外接显示器准备就绪...);
            SystemClock.sleep(2000);
            DISPLAYMANAGER DISPLAYMANAGER =(DISPLAYMANAGER)getSystemService(DISPLAY_SERVICE);
            显示[] presentationDisplays = displayManager.getDisplays(DisplayManager.DISPLAY_CATEGORY_ preSENTATION);
            如果(空== presentationDisplays || presentationDisplays.length == 0){
                Log.d(EXTRA_DISPLAY_TAG,没有找到任何类别presentation显示...);
            }其他{
                externalDisplay = presentationDisplays [0]; // OK:以第一
            }
            //尝试手动选择显示...
            如果(externalDisplay == NULL){
                显示[] = allDisplays displayManager.getDisplays();
                的for(int i = 0; I< allDisplays.length;我++){
                    Log.d(EXTRA_DISPLAY_TAG,检测到显示+第(i + 1)+:+ allDisplays [I] .getName());
                }
                // externalDisplay = allDisplays [0]; // FIXME:由某些标准以...
            }
        }
    }    如果(externalDisplay!= NULL){
        Log.i(EXTRA_DISPLAY_TAG,检测到外接显示器......);
        点大小=新点();
        externalDisplay.getSize(大小);
        INT宽度= size.x;
        INT高度= size.y;
        Log.i(EXTRA_DISPLAY_TAG,外部显示器分辨率:+宽+PX X+高度+PX);
    }    //辞退当前presentation如果显示更改
    如果(量子presentation = NULL&放大器;!&安培;!量子presentation.getDisplay()= externalDisplay){        Log.i(EXTRA_DISPLAY_TAG,离开presentation因为当前路由不再有presentation显示。);
        量子presentation.dismiss();
        量子presentation = NULL;
    }    如果需要的话//显示新的presentation
    如果(量子presentation == NULL和放大器;&安培;!externalDisplay = NULL){
        Log.i(EXTRA_DISPLAY_TAG,陈列显示presentation:+ externalDisplay);
        量子presentation =新的量子presentation(这一点,externalDisplay);
        量子presentation.setOnDismissListener(上presentationDismissListener);
        尝试{
            Log.i(EXTRA_DISPLAY_TAG启动额外的显示器presentation ......);
            量子presentation.show();
        }赶上(WindowManager.InvalidDisplayException前){
            Log.w(EXTRA_DISPLAY_TAG,无法显示presentation其间辗转外接显示器!,前);
            量子presentation = NULL;
        }    }
    //更新活动中玩的内容...
    updateContents();
}


解决方案

银河的Nexus不支持多个独立的显示器,因为有报道:的 HTTPS://$c$c.google.com/p/android/issues/detail ID = 42509

I am trying to use Presenter feature in JellyBean to show custom graphics on additional large screen. I am connected with MHL compliant HDMI adapter (microUSB -> HDMI). Piece of my code trying to detect external display is below. For some reason - I do get output on my external monitor but DisplayManager won't detect external display. I wonder if this has to do with adapter or it would be the case if I connected phone to external display with HDMI cable directly?

My logcat: http://postimg.org/image/sloflge1b/

My code piece:

@SuppressLint("NewApi")
private void updatePresentation() {
    // Get the current route and its presentation display.
    Log.d(EXTRA_DISPLAY_TAG, "Inside updatePresentation() call...");

    MediaRouter.RouteInfo route = mediaRouter.getSelectedRoute(MediaRouter.ROUTE_TYPE_LIVE_VIDEO);

    Log.d(EXTRA_DISPLAY_TAG, "Route name: " + route.getName() + " , route status: " + route.getStatus());
    Display externalDisplay = null;
    if(route != null && route.getName().equals("HDMI")){
        externalDisplay = route.getPresentationDisplay();
        if(externalDisplay == null){ //Maybe not ready...
            Log.d(EXTRA_DISPLAY_TAG, "Waiting for external display to become ready...");
            SystemClock.sleep(2000);
            DisplayManager displayManager = (DisplayManager)getSystemService(DISPLAY_SERVICE);
            Display[] presentationDisplays = displayManager.getDisplays(DisplayManager.DISPLAY_CATEGORY_PRESENTATION);
            if(null == presentationDisplays || presentationDisplays.length == 0){
                Log.d(EXTRA_DISPLAY_TAG, "Didn't find any presentation displays by category...");
            }else{
                externalDisplay = presentationDisplays[0]; //OK: Take first
            }
            //Try to manually select display...
            if(externalDisplay == null){
                Display[] allDisplays = displayManager.getDisplays();
                for(int i=0; i<allDisplays.length; i++){
                    Log.d(EXTRA_DISPLAY_TAG, "Detected display  "+(i+1)+ " : " + allDisplays[i].getName());
                }


                //externalDisplay = allDisplays[0]; //FIXME: Take by some criteria...
            }
        }
    }

    if(externalDisplay != null){
        Log.i(EXTRA_DISPLAY_TAG, "Detected external display...");
        Point size = new Point();
        externalDisplay.getSize(size);
        int width = size.x;
        int height = size.y;
        Log.i(EXTRA_DISPLAY_TAG, "External display resolution: " + width + "px x " + height + "px");
    }

    // Dismiss current presentation if display changes
    if(quantumPresentation != null && quantumPresentation.getDisplay() != externalDisplay){

        Log.i(EXTRA_DISPLAY_TAG, "Leaving presentation because current route no longer has a presentation display.");
        quantumPresentation.dismiss();
        quantumPresentation = null;
    }

    // Show new presentation if needed
    if(quantumPresentation == null && externalDisplay != null) {
        Log.i(EXTRA_DISPLAY_TAG, "Showing presentation on display: "  + externalDisplay);
        quantumPresentation = new QuantumPresentation(this, externalDisplay);
        quantumPresentation.setOnDismissListener(onPresentationDismissListener);            
        try{
            Log.i(EXTRA_DISPLAY_TAG, "Starting additional display presentation...");
            quantumPresentation.show();
        } catch (WindowManager.InvalidDisplayException ex){
            Log.w(EXTRA_DISPLAY_TAG, "Couldn't show presentation! External display was removed in the meantime!", ex);
            quantumPresentation = null;
        }

    }
    // Update the contents playing in activity...
    updateContents();


}

解决方案

The Galaxy Nexus does not support multiple independent displays, as has been reported: https://code.google.com/p/android/issues/detail?id=42509

这篇关于软糖外接显示器与MediaRouter或DISPLAYMANAGER发现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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