问题
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();
}
回答1:
The Galaxy Nexus does not support multiple independent displays, as has been reported: https://code.google.com/p/android/issues/detail?id=42509
来源:https://stackoverflow.com/questions/16699317/jellybean-external-display-not-found-with-mediarouter-or-displaymanager