-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Microsoft.Maui.Devices.Flashlight: Check if supported #13458
Comments
Excellent idea. I'm currently using this workaround: static bool? hasFlashlight = null;
public static async Task<bool> HasFlashlight()
{
if (hasFlashlight is null)
{
try
{
// Trying to turn off the flashlight wil throw if there is no flashlight. I haven't found a better way yet.
await Flashlight.TurnOffAsync();
hasFlashlight = true;
}
catch
{
hasFlashlight = false;
}
}
return (bool)hasFlashlight;
} Of course this has the issue that if someone is using the torch while this code runs, it will be turned off. The chance of that happening in my app is extremely slim. |
Interesting that we don't have this yet because we have it for most other things 😄 Does every platform offer this detection? Are you by any chance offering taking this up yourself @vividos? If you are, feel free to do so, small but valuable addition I would say! |
We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process. |
Yes, I'll do a spec ticket if you want and can also provide a PR. |
I checked the source code and I think it's possible to get an answer of IsSupported for every platform |
@jfversluis I think I found out why Essentials didn't have an
Alternative method names could be |
I would imagine there are other places within Essentials where this was the case. Are there? How did we deal with those? |
I checked every Essentials class; most have a |
I personally use
|
Description
The
Microsoft.Maui.Devices.Flashlight
(andIFlashlight
) API is useful for turning on/off the flashlight on the device's back. Unfortunately, there's no way to check if a flashlight is available in the device at all. When displaying an UI element like a switch, there's no way to hide the UI element when the hardware doesn't support turning on/off.Public API Changes
My suggestion: A new property in
Flashlight
andFlashlight
:The implementation should be fairly easy, since the platform implementations already check if the flashlight is available, and some even have a private
IsSupported
property.Intended Use-Case
The use case would be to check if a flashlight is available before offering the user a way to switch on/off the flashlight.
The text was updated successfully, but these errors were encountered: