Reputation: 2384
I have been wondering if there is any way in the android API (or any other lib/framework) that can help me to detect if my device screen is mirrored using WiDi,Miracast or MHL or basically any other technique for mirroring your screen.
Br, Inx
Upvotes: 9
Views: 17826
Reputation: 315
Since API level 16 (Android 4.1, released in 2012 so rather new when the question was asked) Android has had MediaRouter
API. Adding callback for ROUTE_TYPE_LIVE_VIDEO
subscribes MediaRouter.Callback.onRoutePresentationDisplayChanged
to be called when external display is connected or disconnected. If the app has sound, other option is to track routed output. The output types TYPE_HDMI
and TYPE_REMOTE_SUBMIX
are used for external display.
Upvotes: 0
Reputation: 502
You can't detect but you can remove functionality which mirrors.
No software can mirror if developer option is disabled.
This code will tell whether android can mirror or not.
int CanMirror = Settings.Secure.getInt(this.getContentResolver(), Settings.Global.DEVELOPMENT_SETTINGS_ENABLED , 0);
//returns 1 if can mirror
//returns 0 if can't mirror
Reference : https://stackoverflow.com/a/63971764/11390822
Upvotes: -1
Reputation: 3458
I'm not sure what you are trying to achieve, but if you simply want to disable screenshots and such, you can use FLAG_SECURE
.
Upvotes: -2
Reputation: 99
You may navigate through the list of all device display and get flags on each for finding one with, maybe, VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR ? Not sure but a few trys should allow you to figure out which ones will do it.
cf: DisplayManager and VirtualDisplay documentation
Upvotes: 0