Android 在MediaRouter或DisplayManager中找不到JellyBean外部显示器

Android 在MediaRouter或DisplayManager中找不到JellyBean外部显示器,android,android-4.2-jelly-bean,Android,Android 4.2 Jelly Bean,我正在尝试使用JellyBean中的Presenter功能在额外的大屏幕上显示自定义图形。我使用兼容MHL的HDMI适配器(microUSB->HDMI)连接。下面是我试图检测外部显示的代码。出于某种原因-我确实在外部显示器上获得了输出,但DisplayManager不会检测到外部显示器。我想知道这是否与适配器有关,或者如果我直接用HDMI电缆将手机连接到外部显示器,情况会是这样 我的日志: 我的代码块: @SuppressLint("NewApi") private void updatePr

我正在尝试使用JellyBean中的Presenter功能在额外的大屏幕上显示自定义图形。我使用兼容MHL的HDMI适配器(microUSB->HDMI)连接。下面是我试图检测外部显示的代码。出于某种原因-我确实在外部显示器上获得了输出,但DisplayManager不会检测到外部显示器。我想知道这是否与适配器有关,或者如果我直接用HDMI电缆将手机连接到外部显示器,情况会是这样

我的日志:

我的代码块:

@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();


}
@SuppressLint(“NewApi”)
私有void updatePresentation(){
//获取当前路线及其演示文稿显示。
Log.d(额外的显示标签,“Inside updatePresentation()调用…”);
MediaRouter.RouteInfo route=MediaRouter.getSelectedRoute(MediaRouter.route\u TYPE\u LIVE\u VIDEO);
Log.d(额外的显示标签,“路由名称:“+Route.getName()+”,路由状态:“+Route.getStatus()”);
Display externalDisplay=null;
if(route!=null&&route.getName().equals(“HDMI”)){
externalDisplay=route.getPresentationDisplay();
如果(externalDisplay==null){//可能还没有准备好。。。
Log.d(额外的显示标签,“等待外部显示准备就绪…”);
SystemClock.sleep(2000年);
DisplayManager DisplayManager=(DisplayManager)getSystemService(显示服务);
Display[]presentationDisplays=displayManager.getDisplays(displayManager.Display\u CATEGORY\u PRESENTATION);
if(null==presentationDisplays | | presentationDisplays.length==0){
Log.d(额外的显示标签,“未按类别找到任何演示文稿显示…”);
}否则{
externalDisplay=presentationDisplays[0];//确定:先执行
}
//尝试手动选择显示。。。
if(externalDisplay==null){
Display[]allDisplays=displayManager.getDisplays();

对于(int i=0;i),Galaxy Nexus不支持多个独立的显示器,正如已经报道的那样: