Xamarin Essentials FlashLight

Here's the next feature that Xamarin offers to us: FlashLight

If you for some reason want that at some point your application will be able to turn on the flashlight, you can do it very easy.

First you must open you Xamarin solution, in my case on previously sessions I've working in Essentials project.

Once the Solution is open, we need to set two permissions:

Otherwise in the AndroidManifest.xml add:

Those are for using obviously the Camera and te Flashlight Features.

Alright we're able to codify!!!

Go to Essentials > Views folder and create a new ContentPage named FlashlightPage.

Then on the FlashlightPage.xaml modify all the content for this code:

Then go to the code behind: FlashlightPage.xaml.cs and replace all the content for this lines of code:

As easy as that, just add this view to AppShell.xaml

In that file search this lines of code:

And just below those lines Add this:

Okay, just test the app and check that you flashlight Turns On and Off.

Related Links

Xamarin Essentials FlashLight Documentation

Completed Solution Essentials

Share this post