Is there any way in iOS and Android I can detect if my app is being mirrored (via Miracast/AirPlay/Samsung Smart View), and/or disable mirroring?
Asked
Active
Viewed 1.2k times
0
-
Possibly related: http://stackoverflow.com/a/9822607/295004 – Morrison Chang Oct 06 '16 at 03:01
-
Maybe you need to check all active displays with DisplayManager; if more than one, then it is mirroring or check for VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR or VIRTUAL_DISPLAY_FLAG_OWN_CONTENT_ONLY https://developer.android.com/reference/android/hardware/display/DisplayManager.html – ecle Oct 06 '16 at 03:21
-
@MorrisonChang Yes I'm currently using FLAG_SECURE and it seems to work with Miracast (blank screen on those elements), but doesn't seem to work when I use Smart View to mirror to a Samsung TV. Also, what about AirPlay? – user1118764 Oct 07 '16 at 00:39
-
@ecle how do I check for those 2 flags? I've managed to get the displays using DisplayManager.getDisplays(), then iterate through them to see if FLAG_SECURE is set, and if getDisplayId() is Display.DEFAULT_DISPLAY. With Miracast, FLAG_SECURE isn't set, I'm guessing Smart View sets this, which is why it's being mirrored despite using FLAG_SECURE in my LayoutParams. I'm assuming the mirrored display should have a different displayId though (the Miracast one has a different id), and I can probably use this to detect, but how can I block screen elements from showing in the mirrored display? – user1118764 Oct 07 '16 at 02:31
-
1I should also note that the above detection with DisplayManager doesn't work on Vysor screen mirroring, which is based on ADB. The number of displays detected is 1 despite being mirrored in this case. – user1118764 Oct 07 '16 at 02:43
1 Answers
4
I ended up using DisplayManager.getDisplays() to get the list of displays, and check if the length is >1. If so, screen mirroring is detected.

user1118764
- 9,255
- 18
- 61
- 113
-
-
It's a long time ago, but I think I didn't disable mirroring, but rather, just informed the user that the screen is being mirrored. – user1118764 Nov 15 '17 at 05:58
-
Please provide me the solution how to detect mirroring in android?. – Soni Kumar Apr 16 '20 at 12:35
-
I personally hate apps that prevents mirroring. I think it is very intrusive to decide for me on which screen I can see my phone content. I hope Google will limit this wrong behavior by developers. A user should be able to mirror it's entries phone to any screen he wants. – user1671400 Jul 04 '20 at 20:23
-
with using **scrcpy** software that mirror app, and size of displays is 1 also if recording started before app run it also return 1 – Mahmoud Mabrok Nov 01 '20 at 18:28