Xamarin Essentials adds all kinds of useful APIs in a single NuGet package. Let's learn the basics of Xamarin essentials as we take a look!
It’s normal to use different NuGet packages to add more functionalities when we are developing an app, but it’s important to use as few NuGet packages as possible in order to have the best performance possible. That’s why we are going to learn about Xamarin.Essentials! 😍
What is Xamarin.Essentials?
Xamarin.Essentials gives us different multiplatform APIs that allow us to add features in our application, such as accelerometer, barometer, geocoding, geolocation, among others. The largest advantage is that we can get access to all of these functionalities using JUST ONE NuGet Package named Xamarin.Essentials. In previous versions of Xamarin.Forms, we had to add this NuGet to our project, but now it’s added by default when creating a new project.
To Use it, What Do We Need?
If you have Xamarin.Forms version higher than 4.0, the NuGet Package comes integrated in our project. Otherwise, you just have to do the following steps:
Add from NuGet package: Xamarin.Essentials
What Does Xamarin.Essentials Offer?
I really love how Xamarin.Essentials gives us access to different parts of our device and hardware. We can handle measurement sensors, external applications, hardware functionalities, maps, among others. Let’s see one by one!
Gives Us Access to Almost All of the Measurement Sensors Built into our Device 📏
- Accelerometer: Measures the acceleration of our device.
- Barometer: Allows measuring the environmental pressure.
- Gyroscope: Allows us to track rotation around three primary axes of the device.
- Compass: Provides us with compass data to our device.
- Magnetometer: Quantifies the strength or direction the magnetic signal of a sample.
Allows Us to Use Features of Other Apps that are Outside our Application 📨
- Email: Allow us to send Emails
- Phone Dialer: Opens the dial pad.
- Share: Provides us the ability to send some information (text and files) to an external app.
- SMS: Allows us to send SMS.
- Open Browser: Brings us the facilities to open a web browser.
- Launcher: Allows our application to open a URI to an external app through the system.
- Text-to-Speech: Enables our application to utilize the built-in text-to-speech engines to speak back text from the device.
Grants Us Access to Basic Hardware Info and Features of our Device 📧
- Battery: Provides the level, origin and state of the battery.
- Flashlight: Turns on and off the flashlight of our device.
- Vibrate: Accesses the device’s vibration options.
- Detect Shake: Detects the device shakes.
- Orientation Sensor: Detects the device orientation.
Lets Us Play with Location Information!
- Geocoding: Provides the coordinates and addresses of geographic code and of inverse geographic code.
- Geolocation: Returns the device location using the GPS.
- Maps: Opens the map, and you can add a specific location.
Access to our Device and Application Information
- Device Display Information: Returns the orientation and metrics of the device’s screen.
- Device Information: Returns the device information.
- App Information: Returns the app information, such as device name, idiom, version, device type, etc.
- Version Tracking: Returns the tracking of the versions of the applications and the compilation numbers.
- Connectivity: Allows us to check the status of connectivity and detect changes.
Storage, Converters and General Use Functionalities
- Clipboard: Sets/gets clipboard information.
- Color Converters: Allows us to play with the tonality of colors through System.Drawing.Color.
- File System Helper: Allows us to easily save files in the application data.
- MainThread: Executes code in the main thread of the application.
- Platform Extensions: Helps us with Rect, Size and Point conversions.
- Preferences: Allows us to save the preferences of our application.
- Secure Storage: Helps securely store simple key/value pairs.
- Unit Converters: Helps us to convert units.
I hope this article has helped you to make your applications more efficient and with many more features!
Thanks for reading! 💚
Learn More about Xamarin Essentials
Want to go deeper into Xamarin Essentials? Check out these posts next: