Detect screen mirroring using xamarin.forms.android
Asked Answered
G

2

-1

I want to detect android screen mirroring to pc. I am currently coding in c# Xamarin Forms Android.

What I have done

Here someone recommended to use DisplayManager and VirtualDisplay documentation. But I don't know how to achieve that in code.

Here someone recommended to check DisplayManager.getDisplays(), and see if it's >1. Again not working to detect vysor I tried with code.

Geriatrics answered 27/8, 2020 at 13:46 Comment(1)
Check ProjectMediaManagerand ProjectMedia classesAthalia
G
2

Finally I got the working answer.
Android mirrors like vysor can't mirror without having developer options enabled.
To check whether mirror can be run, check this code below:

//https://mcmap.net/q/138739/-android-how-to-check-if-developer-option-is-enabled

var context = Android.App.Application.Context;
var resolver = context.ApplicationContext.ContentResolver;
if (Settings.Secure.GetInt(resolver, Settings.Global.DevelopmentSettingsEnabled, 0) == 1)
{
//Developer options enabled
//Mean vysor can mirror
}
else
{
//Developer options disabled
//Mean vysor can't mirror now
}

enter image description here

Geriatrics answered 19/9, 2020 at 17:54 Comment(0)
M
4

It is not possible to do so in Android.

Reference

The closest you could get is by using FlagSecure to prevent screenshots.

Macrogamete answered 27/8, 2020 at 20:8 Comment(2)
Please check the answer I have referencedMacrogamete
We both have new thing to learn.Geriatrics
G
2

Finally I got the working answer.
Android mirrors like vysor can't mirror without having developer options enabled.
To check whether mirror can be run, check this code below:

//https://mcmap.net/q/138739/-android-how-to-check-if-developer-option-is-enabled

var context = Android.App.Application.Context;
var resolver = context.ApplicationContext.ContentResolver;
if (Settings.Secure.GetInt(resolver, Settings.Global.DevelopmentSettingsEnabled, 0) == 1)
{
//Developer options enabled
//Mean vysor can mirror
}
else
{
//Developer options disabled
//Mean vysor can't mirror now
}

enter image description here

Geriatrics answered 19/9, 2020 at 17:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.