Chapter 10. Contacts, Camera, and Location

Some of the most vital features used by mobile applications today are based on the new types of data that can be collected by our devices. Features such as GPS location and camera are staples in modern applications such as Instagram or Twitter. It's difficult to develop an application and not use some of these functionalities. So, let's explore our options to take advantage of these new types of data with Xamarin.

In this chapter, we will do the following:

  • Introduce the Xamarin.Mobile library
  • Read the address book on Android and iOS
  • Retrieve the GPS location of our device
  • Pull photos from the camera and photo library

Introducing Xamarin.Mobile

To simplify the development of these features across multiple platforms, Xamarin has developed a library called Xamarin.Mobile. It delivers a single API for accessing the contacts, GPS location, cardinal direction, camera, and photo library for iOS, Android, and even Windows platforms. It also takes advantage of Task Parallel Libraries (TPL) to deliver a modern C# API that will make developers more productive than what their native alternatives would. This gives you the ability to write nice, clean, asynchronous code using the async and await keywords in C#. You can also reuse the same code in iOS and Android, minus a few differences that are required by the Android platform.

To install Xamarin.Mobile, open the Xamarin Component Store in Xamarin Studio and add the Xamarin.Mobile component to a project, as shown in the following screenshot; you're going to be using these features (of the component):

Introducing Xamarin.Mobile

Before we dig further into using Xamarin.Mobile, let's review the namespaces and functionalities available with the library:

  • Xamarin.Contacts: This contains classes classes that enable you to interact with the full address book. It includes everything from the contact's photo, phone numbers, address, e-mail, website, and so on.
  • Xamarin.Geolocation: This combined with the accelerometer gives you access to the device's GPS location including the altitude, heading, longitude, latitude, and speed. You can track the device's position explicitly or listen for GPS position changes over time.
  • Xamarin.Media: This grants access to the device's camera (or cameras if there are more than one) and built-in photo library. This is an easy way to add photo selection capabilities to any application.

For the full documentation of Xamarin.Mobile, visit the API documentation included with the Component Store at http://componentsapi.xamarin.com. You can also view it in the native Mono documentation browser by clicking on Open API Documentation when viewing the component in Xamarin Studio.

Xamarin.Mobile is also an open source project with the standard Apache 2.0 license. You can contribute to the project or submit issues to the GitHub page at https://github.com/xamarin/Xamarin.Mobile. Feel free to use Xamarin.Mobile in your applications, or fork and modify it for your own purposes.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.142.250.114