Inx
Inx

Reputation: 2384

how to detect screen mirroring

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

Answers (4)

ojs
ojs

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

Sorry IwontTell
Sorry IwontTell

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

Yuichi Araki
Yuichi Araki

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

Rémi Cohen-Scali
Rémi Cohen-Scali

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

Related Questions