Jaa


Marshmallow Features

This article helps you get started using in using Xamarin.Android to develop apps for Android 6.0 Marshmallow.

This article provides an outline of the new features in Android 6.0 Marshmallow, explains how to prepare Xamarin.Android for Android Marshmallow development, and provides links to sample applications that illustrate how to make use of new Android Marshmallow features in Xamarin.Android apps.

Overview

Android 6.0 Marshmallow, is the next major Android release after Android Lollipop. Xamarin.Android supports Android Marshmallow and includes:

  • API 23/Android 6.0 Bindings – Android 6.0 adds many new APIs for the new features described below; these APIs are available to Xamarin.Android apps when you target API Level 23. For more information about Android 6.0 APIs, see Android 6.0 APIs.

Hero images of tablets and phones running Marshmallow

Although the Marshmallow release is mainly focused on "polish and quality", it also provides many new features of interest to Xamarin.Android developers. These features include:

  • Runtime Permissions – This enhancement makes it possible for users to approve security permissions on a case-by-case basis at run time.

  • Authentication Improvements – Starting with Android Marshmallow, apps can now use fingerprint sensors to authenticate users, and a new confirm credential feature minimizes the need for entering passwords.

  • App Linking – This feature helps to eliminate the necessity of having the App Chooser pop up by automatically associating apps with web domains.

  • Direct Share – You can define direct share targets that make sharing quick and intuitive for users; this feature allows uers to share content with other apps.

  • Voice Interactions – This new API allows you to build conversational voice features into your app.

  • 4K Display Mode – In Android Marshmallow, your app can request a 4K display resolution on hardware that supports it.

  • New Audio Features – Starting with Marshmallow, Android now supports the MIDI protocol. It also provides new classes to create digital audio capture and playback objects, and it offers new API hooks for associating audio and input devices.

  • New Video Features – Marshmallow provides a new class that helps apps render audio and video streams in sync; this class also provides support for dynamic playback rate.

  • Android for Work – Marshmallow includes enhanced controls for corporate-owned, single-user devices. It supports silent install and uninstall of apps by the device owner, auto-acceptance of system updates, improved certificate management, data usage tracking, permissions management, and work status notifications.

  • Material Design Support Library – The new Design Support Library provides design components and patterns that makes it easier for you to build Material Design look and feel into your app.

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

In addition, many core Android library updates were released with Android Marshmallow, and these updates provide new features for both Android Marshmallow and earlier versions of Android. This article explains how to get started building apps with Android Marshmallow, and it provides an overview of the new feature highlights in Android 6.0.

Requirements

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

  • Xamarin.Android – Xamarin.Android 5.1.7.12 or later must be installed and configured with either Visual Studio or Xamarin Studio.

  • Visual Studio for Mac or Visual Studio – If you are using Visual Studio for Mac, version 5.9.7.22 or later is required. If you are using Visual Studio, version 3.11.1537 or later of the Xamarin tools for Visual Studio is required.

  • Android SDK – Android SDK 6.0 (API 23) or later must be installed via the Android SDK Manager.

  • Java Developer Kit – Xamarin.Android requires JDK 1.8 or later if you are developing for API level 24 or greater (JDK 1.8 also supports API levels earlier than 24, including Marshmallow). The 64-bit version of JDK 1.8 is required if you are using custom controls or the Forms Previewer.

You can continue to use JDK 1.7 if you are developing specifically for API level 23 or earlier.

Getting Started

To get started using Android Marshmallow with Xamarin.Android, you must download and install the latest tools and SDK packages before you can create an Android Marshmallow project:

  1. Install the latest Xamarin updates from the Stable channel.

  2. Install the Android 6.0 Marshmallow SDK packages and tools.

  3. Create a new Xamarin.Android project that targets Android 6.0 Marshmallow (API Level 23).

  4. Configure an emulator or device for Android Marshmallow.

Each of these steps is explained in the following sections:

Install Xamarin Updates

To update Xamarin so that it includes support for Android 6.0 Marshmallow, change the update channel to Stable and install all updates. For more information about installing updates from the updates channel, see Change the Updates Channel.

Install the Android 6.0 SDK

To create a Xamarin.Android project for Android Marshmallow, you must first use the Android SDK Manager to install the Android 6.0 SDK:

  • Start the Android SDK Manager (in Visual Studio for Mac, use Tools > SDK Manager; in Visual Studio, use Tools > Android > Android SDK Manager) and install the latest Android SDK Tools:

    Selecting Android SDK tools in the Android SDK Manager

  • Also, install the latest Android 6.0 SDK packages:

    Selecting Android 6.0 SDK packages in the Android SDK Manager

You must install Android SDK Tools revision 24.3.4 or later. For more information about using the Android SDK Manager to install the Android 6.0 SDK, see SDK Manager.

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 6.0 MarshMallow. To target your project for Marshmallow, you must configure your project for API level 23 (Xamarin.Android v6.0 Support). For more about configuring Android API level levels, see Understanding Android API Levels.

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.
  • Target: Android 6.0 - API Level 23
  • ABI: x86

For example, this virtual device is configured to emulate a Nexus 5:

Configuring an AVD using Nexus 5 device, Android 6.0 Target, and Intel Atom (x86)

If you are using a physical device such as a Nexus 5, 6, or 9, you can install a preview image of Android Marshmallow. For more information about updating your device to Android Marshmallow, see Hardware System Images.

New Features

Many of the changes introduced in Android Marshmallow are focused on improving the Android user experience, increasing performance, and fixing bugs. However, Marshmallow also introduced some extensive changes to the fundamentals of the Android platform. The following sections highlight these enhancements and provide links to help you get started in using the new Android Marshmallow features in your app.

Runtime Permissions

The Android Permissions system has been significantly optimized and simplified since Android Lollipop. In Android Marshmallow, users grant permissions on a case-by-case basis at runtime rather than at install time. To support this feature on Android Marshmallow 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.

See Requesting Runtime Permissions in Android Marshmallow for more details (including code examples) about implementing Runtime Permissions in Xamarin.Android apps.

For more information about the new runtime permissions features in Android Marshmallow, see Working with System Permissions.

Authentication Enhancements

Android Marshmallow includes two authentication enhancements that help eliminate the need for passwords:

  • Fingerprint Authentication – Uses a fingerprint scan to authenticate users.

  • Confirm Credential – Authenticates users based on how long the device has been unlocked.

The links and sample apps described next can help you become familiar with these new features.

Fingerprint Authentication

On devices that support fingerprint scanning hardware, you can use the new FingerPrintManager class to authenticate a user. For more information about the fingerprint authentication feature in Android Marshmallow, see Fingerprint Authentication.

Voice Interactions

The new Voice Interactions feature introduced in Android Marshmallow allows users of your app to use their voice to confirm actions and select from a list of options. For more information about Voice Interactions, see Overview of the Voice Interaction API.

See Add a Conversation to your Android App with Voice Interactions for more details (including code examples) about implementing Voice Interactions in Xamarin.Android apps. A sample app is available that illustrates how to use the Voice Interaction API in a Xamarin.Android app: Voice Interactions.

Confirm Credential

Using the new confirm credential feature of Android Marshmallow, 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's CreateConfirmDeviceCredentialIntent method to re-authenticate the user from within your app. For more information about this new feature in Android Marshmallow, see Confirm Credential.

Chrome Custom Tabs

App developers face a choice when a user taps a URL: the app can either launch a browser or use an in-app browser based on a WebView. Both options present challenges – launching the browser is a heavy context switch that isn't customizable, while WebViews do not share state with the browser. Also, use of WebViews can add extra maintenance overhead.

Chrome Custom Tabs makes it possible for you to easily and elegantly display websites with the power of Chrome without having your users leave your app. This feature gives your app more control over the user's web experience; it make transitions between native and web content more seamless without having to resort to a WebView. Your app can also affect how Chrome looks and feels by customizing the following:

  • Toolbar color

  • Enter and exit animations

  • Custom actions in the Chrome toolbar and overflow menu

  • Chrome pre-start and content pre-fetch (for faster loading)

To take advantage of this feature in your Xamarin.Android app, download and install the Android Support Custom Tabs Library. For more information about this feature, see Chrome Custom Tabs.

Material Design Support Library

Android Lollipop introduced Material Design as a new design language to refresh the Android experience (see Material Theme for information about using material design in Xamarin.Android apps). With Android Marshmallow, Google introduced the Android Design Support Library to make it easier for app developers to adopt material design look and feel. This library includes the following components:

  • CoordinatorLayout – The new CoordinatorLayout widget is similar to but more powerful than a FrameLayout. You can use CoordinatorLayout as a container for child views or as a top-level layout, and it provides a layout_anchor attribute that can be used to anchor views relative to other views.

  • Collapsing Toolbars – The new CollapsingToolbarLayout is a collapsing app bar that is a wrapper for Toolbar. (Note that the app bar is what was formerly referred to as the action bar.)

  • Floating Action Button – A round button that denotes the primary action on your app's interface.

  • Floating Labels for Editing Text – Uses a new TextInputLayout widget (which wraps EditText) to show a floating label when a hint is hidden when a user inputs text.

  • Navigation View – The new NavigationView widget helps you use the navigation drawer in a way that is easier for users to navigate.

  • Snackbar – The new SnackBar widget is a lightweight feedback mechanism (similar to a toast) that displays a brief message at the bottom of the screen, appearing above all other elements on the screen.

  • Material Tabs – The new TabLayout widget provides a horizontal layout for displaying tabs as way to implement top-level navigation in your app.

To take advantage of the Design Support Library in your Xamarin.Android app, download and install the Xamarin Xamarin Support Library Design NuGet package.

See Beautiful Material Design with the Android Support Design Library for more details (including code examples) about using the Material Design Support Library in Xamarin.Android apps.

For more information about the Design library, see Android Design Support Library in the Android Developer's blog.

Additional Library Updates

In addition to Android Marshmallow, Google has announced related updates to several core Android libraries. Xamarin provides Xamarin.Android support for these updates through several preview-release NuGet packages:

  • Google Play Services – The latest version of Google Play Services includes the new App Invites feature, which makes it possible for users to share their app with friends. For more information about this feature, see Expand Your App's Reach with Google's App Invites.

  • Android Support Libraries – These NuGets offer features that are only available for library APIs while providing backward-compatible versions of the Android framework APIs.

  • Android Wearable Library – this NuGet includes Google Play Services bindings. The latest version of the wearable library brings new features (including easier navigation for custom apps) to the Android Wear platform.

Summary

This article introduced Android Marshmallow and explained how to install and configure the latest tools and packages for Xamarin.Android development on Marshmallow. It also provided an overview of the most exciting new Android Marshmallow features for Xamarin.Android development.