April 23rd, 2020

Xamarin.Essentials: Now with Permissions, App Theme, & Authentication

James Montemagno
Principal Manager, Tech PM

Since the first release of Xamarin.Essentials, developers have enjoyed the simplification of complex native features into a single cross-platform library. They can do this across iOS, Android, UWP, Tizen, watchOS, and even tvOS! No matter what type of app you are writing, there is absolutely something in Xamarin.Essentials for you. With the recent release of Xamarin.Essentials 1.5, even more cross-platform capabilities are unlocked for developers. Let us review just a few features that you can access right now.

Logo for Xamarin.Essentials

App Theme Just about every operating system has fully embraced dark mode for apps. Checking what the user has selected as their device default should be easy. Which is why we included a new way to select the requested theme.

AppTheme appTheme = AppInfo.RequestedTheme;
 When using this new API and dynamic themes, easily enable your app to react to light/dark mode changes: 

Image App Theme Support in Xamarin Essentials
Checkout the

MyContacts sample on GitHub for a real-world sample. Then watch the Xamarin.Essentials API of the Week on App Theme:

 

Permissions Want to use geolocation, contacts, or the camera? You will need to ask for permission from your users. Xamarin.Essentials makes this easier than ever with just a few lines of code. Simply add the permissions into your application configuration, then check and request permissions from your shared code:

public async Task<permissionstatus> CheckAndRequestLocationPermission()
{
    var status = await Permissions.CheckStatusAsync<Permissions.LocationWhenInUse>();
    if (status != PermissionStatus.Granted)
    {
        status = await Permissions.RequestAsync<Permissions.LocationWhenInUse>();
    }

    // Additionally could prompt the user to turn on in settings

    return status;
}
</permissionstatus>

Image Check Permissions with Xamarin Essentials
Want more? Checkout the full Xamarin.Essentials API of the Week video:

Web Authentication Looking to add authentication to your mobile app? Xamarin.Essentials has you covered! It pairs beautifully with ASP.NET Core.

Image Web Authentication with Xamarin Essentials

Jon Dick just did a full blog post on how to setup web authentication with Xamarin.Essentials. If needed, read through Jon’s blog to get set up and then come back to this post.

What is Next? We are glad that you asked! At the

.NET Conf – Focus on Xamarin event, we announced our plans for Xamarin.Essentials 1.6. This release will include official support for macOS. Additionally, there will be integration of amazing community pull requests. PRs including File Picker, Haptic Feedback, App Actions, Calendar, and more! Be sure to Like and Follow Xamarin.Essentials on GitHub.

Get Started Xamarin.Essentials is included with every project template! Make sure you upgrade to the latest version in NuGet today. Integrate Xamarin.Essentials into an existing app through our

getting started documentation.

Author

James Montemagno
Principal Manager, Tech PM

James Montemagno is a Principal Lead Program Manager for Developer Community at Microsoft. He has been a .NET developer since 2005, working in a wide range of industries including game development, printer software, and web services. Prior to becoming a Principal Program Manager, James was a professional mobile developer and has now been crafting apps since 2011 with Xamarin. In his spare time, he is most likely cycling around Seattle or guzzling gallons of coffee at a local coffee shop. He ...

More about author

3 comments

Discussion is closed. Login to edit/delete existing comments.

  • Carlos Cuenta

    Hi everybody, hi James. I have been for MONTHS looking for help to solve a conflict on permissions in Xamarin
    I am having trouble copying a file. I don’t know if you can help me by checking the code here.
    Regards.

  • Tushar Upadhyay

    This made my work today.

  • Hertzy Tambwe

    This really very interesting.