Hello,
Welcome to our Microsoft Q&A platform!
You do not need to use camera to detect the light, lots of android devices have a light sensor.
For Android, you should SensorManager
to get the light value.
SensorManager _senMan = (SensorManager)GetSystemService(Context.SensorService);
Sensor sen = _senMan.GetDefaultSensor(SensorType.Light);
_senMan.RegisterListener(new MySensorListner(_senMan,this), sen, Android.Hardware.SensorDelay.Game);
internal class MySensorListner : Java.Lang.Object, ISensorEventListener
{
SensorManager _senMan;
MainActivity mainActivity;
public MySensorListner(SensorManager _senMan, MainActivity mainActivity)
{
this._senMan = _senMan;
this.mainActivity = mainActivity;
}
public void OnAccuracyChanged(Sensor sensor, [GeneratedEnum] SensorStatus accuracy)
{
}
public void OnSensorChanged(SensorEvent s)
{
// get lightSensor value.
s.Sensor = _senMan.GetDefaultSensor(SensorType.Light);
float lightSensorValue = s.Values[0];
Toast.MakeText(mainActivity, lightSensorValue.ToString("0.00"), ToastLength.Long).Show();
}
}
}
Based on the lightSensorValue, you should detect if light is ON or OFF.
Best Regards,
Leon Lu
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.