C# is the best language for mobile app development. With Xamarin, you write your apps entirely in C#, sharing the same code on iOS, Android, Windows, Mac and more. Anything you can do in Objective-C, Swift or Java, you can do in C#.

Xamarin apps share code across all platforms.It target iOS, Android, Windows and Mac with a single, shared C# codebase. Use the same language, APIs and data structures on every platform.

Xamarin.Android uses just-in-time compilation for sophisticated runtime optimization of your app’s performance, meaning your app is a native Android APK. Access any Android API, including new form factors. Xamarin bring 100% of Google’s Android APIs to C#, enhancing Java APIs with async support and .NET naming conventions so you feel right at home.

With access to 100% API support for Android Wear, create full-featured applications capable of running on Android Wear devicesXamarin stays up-to-date with the most current APIs from Google, so you can always use the latest features in your apps.

This article post explains how to download and install the Preview SDK to create applications using Xamarin.Android.

Android library updates were released with Android M, and these updates provide new features for both Android M and earlier versions of Android.

The Xamarin.Android preview supports the Android M Preview and includes:

  • API 22/Android 5.1 Bindings – Android 5.1 is an update to Lollipop that adds Multiple SIM Card support and support for carrier services.

Let’s discover how to get started building apps with the Android M preview and overview of the new feature highlights in Android M.

Note: You cannot publish Android M Developer Preview apps to the Google Play store as for now.

Requirements

The following is required to use the new Android M features in Xamarin-based apps

  • Xamarin.Android: Xamarin.Android 5.1.77 or later must be installed and configured with either Visual Studio or Xamarin Studio. If you are using Xamarin Studio, version 5.9.4 or later is required. Download here.
  • Android SDK: Android M or later must be installed via the Android SDK Manager. Download it here.
  • Java JDK 1.7: Android M requires JDK 1.7 for compilation of applications; JDK 1.7 is available from Oracle.

Procedure

Download and install the latest tools and SDK packages before you can create an Android M project

  1. Install the Android M Preview SDK packages and tools.
  2. Download and install the Xamarin.Android M Web Preview.
  3. Create a new Xamarin. The Android project that targets Android M.
  4. Configure an emulator or device for Android M.

Install the Android Preview SDK

To create a Xamarin.Android project for Android M, you must first use the Android SDK Manager to install the Android MNC Preview:

  • Start the Android SDK Manager (in Xamarin Studio, use Tools > Open Android SDK Manager…) and install the latest Android SDK Tools:

Also, install the latest Android MNC Preview SDK packages:

  • You must install Android SDK Tools revision 24.3 or later. [For Compatibility]

Download and Install the Xamarin.Android M Preview

Download the correct installers for your computer.

Windows:

Mac OS X users must install:

Start a Xamarin.Android Project

Create a new Xamarin.Android project. If you are new to Android development with Xamarin, see Hello, Android to learn about creating Android projects.

When you create an Android project, you must configure the version settings to target Android M. To target your project for Android M, you must configure the appropriate Android API level. Currently, there is limited IDE support for setting the Android SDK version to M. In Xamarin Studio, navigate to Project Options > Build > Android Application and set Minimum SDK Version to v5.1 (22) or lower (do not set the minimum SDK version to Automatic or to v5.2 (23)).

For now you must use the v5.1 (22) or lower setting in order to deploy to M devices and emulators (this bug will be fixed in a future release).

Configure an Emulator or Device

If you are using an emulator, start the Android AVD Manager and create a new device using the following settings:

  • Device: Nexus 5, 6, or 9. (Nexus 5 is recommended)
  • Target: Android M (Preview) – API Level MNC
  • ABI: x86

For example, this virtual device is configured to emulate a Nexus 5 (only difference in Device drop-down menu)

New Features

Runtime Permissions

The Android Permissions system has been significantly optimized and simplified since Android Lollipop. In Android M, users grant permissions on a case-by-case basis at runtime rather than at install time. To support this feature on Android M and later, you design your app to prompt the user for permissions at runtime (in the context of where the permissions are needed). This change makes it easier for users to start using your app immediately because it streamlines the process of installing and upgrading your app.

A sample app that illustrates how runtime permissions work in Android M (and later)- Link

This sample app demonstrates the following:

  • How to check and request permissions at runtime.
  • How to declare permissions for Android M devices.

To use this sample app:

  1. Tap the Camera or Contacts buttons to display a permissions request dialog.
  2. Grant permission to view Camera or Contacts fragments.

Fingerprint Authentication

On devices that support fingerprint scanning hardware, you can use the new FingerPrintManager class to authenticate a user.

Xamarin provides a sample app that illustrates how to use registered fingerprints to authenticate a user in your app: FingerprintDialog.

To use this sample app:

  1. Touch the Purchase button to open a fingerprint authentication dialog.
  2. Scan in your registered fingerprint to authenticate.

Note: This sample app requires a device with a fingerprint reader. This app does not store your fingerprint.

Confirm Credential

Using the new confirm credential feature of Android M, you can free users from having to remember and enter app-specific passwords by authenticating them based on how long their device has been unlocked. To do this, you use the new SetUserAuthenticationValidityDurationSeconds method of the KeyGenerator. Use the KeyGuardManager‘sCreateConfirmDeviceCredentialIntent method to re-authenticate the user from within your app.

A sample for testing confirm credential – Link

To use this sample app:

  1. Setup a secure lock screen on your device (Secure > Security > Screen lock).
  2. Tap the Purchase button and confirm the secure lock screen credentials.

Chrome Custom Tabs

Chrome custom tabs give apps more control over their web experience and make transitions between native and web content more seamless without having to resort to a WebView.

Chrome custom tabs allow an app to customize how Chrome looks and feels. An app can change things like:

  • Toolbar color
  • Enter and exit animations
  • Add custom actions to the Chrome toolbar and overflow menu

To take advantage of this feature in your Xamarin.Android app, download and install the Chrome Custom Tabs for Xamarin.Android NuGet package.

Sample: Currently, this is available as Chrome Dev in the Google Play Store (Requires Chrome version 44 or above)

Once you have installed Chrome Dev, do the following before running the sample app:

  1. Enter the following into the browser:
chrome://flags

2. Find Enable Hosted Mode and tap Enable.

Now you’re good to go. Explore the new possibilities with Xamarin.Android and move the world.

If you find this post helpful, do comment below and if you have any difficulty setting up Xamarin.Android we are ready to help you out. Share your experiences with Xamarin. Android in the comment section below.

This site uses Akismet to reduce spam. Learn how your comment data is processed.