How to detect external displays in android prior API 17

半城伤御伤魂 提交于 2021-02-06 11:23:55

问题


I'm working in app that has copyrighted videos that should work only in Android device and not in external display connected via HDMI or wirelessly. I found great API Presentation and DisplayManager to detect and control which content to be displayed on external displays but this API's available only in API 17 (android 4.2) and plus. Any idea in how to do this below android 4.2 or at least to detect and be notified for connected displays.

Question #2: What about if android device is connected to PC for screen recording. Can Presentation or DisplayManager API help to detect that?


回答1:


Any idea in how to do this below android 4.2 or at least to detect and be notified for connected displays.

Beyond possibly MediaRouter in API Level 16 as noted in Distwo's answer, there was no support for app-level access to external displays in older versions of Android. Relatively few devices even supported external displays; those that did only offered OS-level screen mirroring.

Your best bet, if you want to call it that, is to get your hands on a few such devices and see if there are any common LogCat messages that indicate the existence of external displays, or maybe some Linux-level stuff in /proc. However, there is a very good chance that these will wind up being different by manufacturer and device.

What about if android device is connected to PC for screen recording. Can Presentation or DisplayManager API help to detect that?

No.




回答2:


Going back to API 16 you can use MediaRouter class. Cf android developer website.

To get the default display for your presentation, call MediaRouter.getSelectedRoute() and pass it ROUTE_TYPE_LIVE_VIDEO. This returns a MediaRouter.RouteInfo object that describes the system’s currently selected route for video presentations. If the MediaRouter.RouteInfo is not null, call getPresentationDisplay() to get the Display representing the connected display.

Full source: http://developer.android.com/about/versions/android-4.2.html#SecondaryDisplays



来源:https://stackoverflow.com/questions/32498834/how-to-detect-external-displays-in-android-prior-api-17

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