Jaa


Oreo Features

How to get started using Xamarin.Android to develop apps for the latest version of Android.

Android 8.0 Oreo is the latest version of Android available from Google. Android Oreo offers many new features of interest to Xamarin.Android developers. These features include notification channels, notification badges, custom fonts in XML, downloadable fonts, autofill, and picture in picture (PIP). Android Oreo includes new APIs for these new capabilities, and these APIs are available to Xamarin.Android apps when you use Xamarin.Android 8.0 and later.

Android Oreo hero image

This article is structured to help you get started in developing Xamarin.Android apps for Android 8.0 Oreo. It explains how to install the necessary updates, configure the SDK, and create an emulator (or device) for testing. It also provides an outline of the new features in Android 8.0 Oreo, with links to sample apps that illustrate how to use Android Oreo features in Xamarin.Android apps.

Requirements

The following is required to use Android Oreo features in Xamarin-based apps:

  • Visual Studio – If you are using Windows, version 15.5 or later of Visual Studio is required. If you are using a Mac, Visual Studio for Mac version 7.2.0 is required.

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

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

Getting Started

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

  1. Update to the latest version of Visual Studio.

  2. Install the Android 8.0.0 (API 26) or later packages and tools via the SDK Manager.

  3. Create a new Xamarin.Android project that targets Android Oreo (API 26).

  4. Configure an emulator or device for testing Android Oreo apps.

Each of these steps is explained in the following sections:

Update Visual Studio and Xamarin.Android

To add Android Oreo support to Visual Studio, do the following:

  • For Visual Studio 2019, use the SDK Manager to install API level 26.0 or later.

  • If you are using Visual Studio 2017:

    1. Update to Visual Studio 2017 version 15.7 or later (see Update Visual Studio 2017).

    2. Use the SDK Manager to install API level 26.0 or later.

For more information about Xamarin support for Android Oreo, see the Xamarin.Android 8.0 release notes.

Install the Android SDK

To create a project with Xamarin.Android 8.0, you must first use the Xamarin Android SDK Manager to install the SDK platform for Android 8.0 - Oreo or later. You must also install Android SDK Tools 26.0 or later.

  1. Start the SDK Manager (in Visual Studio, click Tools > Android > Android SDK Manager).

  2. Install the Android 8.0 - Oreo packages. If you are using the Android SDK emulator, be sure to include the x86 system images that you will need:

    Selecting Android 8.0 packages in the Android SDK Manager

  3. Install Android SDK Tools 26.0.2 or later, Android SDK Platform-Tools 26.0.0 or later, and Android SDK Build-Tools 26.0.0 (or later):

    Selecting Android SDK Tools 26 in the Android 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 Xamarin.Android projects.

When you create an Android project, you must configure the version settings to target Android 8.0 or later. For example, to target your project for Android 8.0, you must configure the target Android API level of your project to Android 8.0 (API 26). It is recommended that you also set your target framework level to API 26 or later. For more about configuring Android API level levels, see Understanding Android API Levels.

Configure an Emulator or Device

If you attempt to launch the default Google GUI-based AVD Manager after installing Android SDK Tools 26.0 or later, you may get the following error dialog, which instructs you to use the command line AVD manager tool avdmanager instead:

This message is displayed because Google no longer provides a standalone GUI AVD manager that supports API 26.0 and later. For Android 8.0 Oreo, you must use either the Xamarin Android Emulator Manager or the command-line avdmanager tool to create virtual devices for Android Oreo.

To use the Android Device Manager to create and manage virtual devices, see Managing Virtual Devices with the Android Device Manager. To create virtual devices without the Android Device Manager, follow the steps in the next section.

Creating Virtual Devices Using avdmanager

To use avdmanager to create a new virtual device, follow these steps:

  1. Open a Command Prompt window and set JAVA_HOME to the location of the Java SDK on your computer. For a typical Xamarin installation, you can use the following command:

    setx JAVA_HOME "C:\Program Files\Java\jdk1.8.0_131"
    
  2. Add the location of the Android SDK bin folder to your PATH. For a typical Xamarin installation, you can use the following command:

    setx PATH "%PATH%;C:\Program Files (x86)\Android\android-sdk\tools\bin"
    
  3. Close the Command Prompt window and open a new Command Prompt window. Create a new virtual device by using the avdmanager command. For example, to create an AVD named AVD-Oreo-8.0 using the x86 system image for API level 26, use the following command:

    avdmanager create avd -n AVD-Oreo-8.0 -k "system-images;android-26;google_apis;x86"
    
  4. When you are prompted with Do you wish to create a custom hardware profile [no] you can enter no and accept the default hardware profile. If you say yes, avdmanager will prompt you with a list of questions for customizing the hardware profile.

After you avdmanager to create your virtual device, it will be included in the device pull-down menu:

New AVD added to device pull-down menu

For more information about configuring an Android emulator for testing and debugging, see Debugging on the Android Emulator.

If you are using a physical device such as a Nexus or a Pixel, you can either update your device through automatic over the air (OTA) updates or download a system image and flash your device directly. For more information about manually updating your device to Android Oreo, see Factory Images for Nexus and Pixel Devices.

New Features

Android Oreo introduces a variety of new features and capabilities, such as notification channels, notification badges, custom fonts in XML, downloadable fonts, autofill, and picture-in-picture. The following sections highlight these features and provide links to help you get started using them in your app.

Notification Channels

Notification Channels are app-defined categories for notifications. You can create a notification channel for each type of notification that you need to send, and you can create notification channels to reflect choices made by users of your app. The new notification channels feature makes it possible for you to give users fine-grained control over different kinds of notifications. For example, if you are implementing a messaging app, you can create separate notification channels for each conversation group that is created by a user.

Notification Channels explains how to create a notification channel and use it for posting local notifications.

Notification Badges

Notification badges are small dots that appear over app icons as shown in this screenshot:

Example notification badges on app icons

These dots indicate that there are new notifications for one or more notification channels in the app associated with that app icon – these are notifications that the user has not yet dismissed or acted upon. Users can long-press on an icon to glance at the notifications associated with a notification badge, dismissing or acting on notifications from the long-press menu that appeaars.

For more information about notification badges, see the Android Developer Notification Badges topic.

Custom Fonts in XML

Android Oreo introduces Fonts in XML, which makes it possible for you to incorporate custom fonts as resources. OpenType (.otf) and TrueType (.ttf) font formats are supported. To add fonts as resources, do the following:

  1. Create a Resources/font folder.

  2. Copy your font files (example, .ttf and .otf files) to Resources/font.

  3. If necessary, rename each font file so that it adheres to the Android file naming conventions (i.e., use only lowercase a-z, 0-9, and underscores in file names). For example, the font file Pacifico-Regular.ttf could be renamed to something like pacifico.ttf.

  4. Apply the custom font by using the new android:fontFamily attribute in your layout XML. For example, the following TextView declaration uses the added pacifico.ttf font resource:

    <TextView
      android:text="Example Text in Pacifico Regular"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:fontFamily="@font/pacifico" />
    

You can also create a font family XML file that describes multiple fonts as well as style and weight details. For more information, see the Android Developer Fonts in XML topic.

Downloadable Fonts

Beginning with Android Oreo, apps can request fonts from a provider rather than bundling them into the APK. Fonts are downloaded from the network only as needed. This feature reduces APK size, conserving phone memory and cellular data usage. You can also use this feature on Android API versions 14 and higher by installing the Android Support Library 26 package.

When your app needs a font, you create a FontsRequest object (specifying the font to download) and then pass it to a FontsContract method to download the font. The following steps describe the font download process in more detail:

  1. Instantiate a FontRequest object.

  2. Subclass and instantiate FontsContract.FontRequestCallback.

  3. Implement the FontRequestCallback.OnTypeFaceRetrieved method, which is used to handle completion of the font request.

  4. Implement the FontRequestCallback.OnTypeFaceRequestFailed method, which is used to inform your app of any errors that take place during the font request process.

  5. Call the FontsContract.RequestFonts method to retrieve the font from the font provider.

When you call the RequestFonts method, it first checks to see if the font is locally cached (from a previous call to RequestFont). If it is not cached, it calls the font provider, retrieves the font asynchronously, and then passes the results back to your app by invoking your OnTypeFaceRetrieved method.

For more information about downloading fonts, see the Android Developer Downloadable Fonts topic.

Autofill

The new Autofill framework in Android Oreo makes it easier for users to handle repetitive tasks such as login, account creation, and credit card transactions. Users spend less time re-typing information (which can lead to input errors). Before your app can work with the Autofill Framework, an autofill service must be enabled in the system settings (users can enable or disable autofill).

For more information about the new Autofill feature and how to optimize your app for autofill, see the Android Developer Autofill Framework topic.

Picture in Picture (PIP)

Android Oreo makes it possible for an Activity to launch in picture-in-picture (PIP) mode, overlaying the screen of another Activity. This feature is intended for video playback.

To specify that your app's Activity can use PIP mode, set the following flag to true in the Android manifest:

android:supportsPictureInPicture

To specify how your activity should behave when it is in PIP mode, you use the new PictureInPictureParams object. PictureInPictureParams represents a set of parameters that you use to initialize and update an Activity in PIP mode (for example, the Activity's preferred aspect ratio). The following new PIP methods were added to Activity in Android Oreo:

  • EnterPictureInPictureMode – puts the Activity in PIP mode. The Activity is placed in the corner of the screen, and the rest of the screen is filled with the previous Activity that was on the screen.

  • SetPictureInPictureParams – Updates the Activity's PIP configuration settings (for example, a change in aspect ratio).

Other Features

Android Oreo contains many other new features such as the Emoji support library, Location API, background limits, wide-gamut color for apps, new audio codecs, WebView enhancements, improved keyboard navigation support, and a new AAudio (pro audio) API for high-performance low-latency audio, For more information about these features, see the Android Developer Android Oreo Features and APIs topic.

Behavior Changes

Android Oreo includes a variety of system and API behavior changes that can have an impact on the functionality of existing apps. These changes are described as follows.

Background Execution Limits

To improve the user experience, Android Oreo imposes limitations on what apps can do while running in the background. For example, if the user is watching a video or playing a game, an app running in the background could impair the performance of a video-intensive app running in the foreground. As a result, Android Oreo places the following restrictions on apps that are not directly interacting with the user:

  1. Background Service Limitations – When an app is running in the background, it has a window of several minutes in which it is still allowed to create and use services. At the end of that window, Android stops the app's background service and treats it as being idle.

  2. Broadcast Limitations – Android 7.0 (API 25) placed limitations on broadcasts that an app registers to receive. Android Oreo makes these limitations more stringent. For example, Android Oreo apps can no longer register broadcast receivers for implicit broadcasts in their manifests.

For more information about the new background execution limits, see the Android Developer Background Execution Limits topic.

Breaking Changes

Apps that target Android Oreo or higher must modify their apps to support the following changes, where applicable:

  • Android Oreo deprecates the ability to set the priority of individual notifications. Instead, you set a recommended importance level when creating a notification channel. The importance level you assign to a notification channel applies to all notification messages that you post to it.

  • For apps targeting Android Oreo, PendingIntent.GetService() does not work due to new limits placed on services started in the background. If you are targeting Android Oreo, you should use PendingIntent.GetBroadcast instead.

Video

Android 8.0 Oreo development with C#

Summary

This article introduced Android Oreo and explained how to install and configure the latest tools and packages for Xamarin.Android development on Android Oreo. It provided an overview of the key features available in Android Oreo, with links to example source code for several new features. It included links to API documentation and Android Developer topics to help you get started in creating apps for Android Oreo. It also highlighted the most important Android Oreo behavior changes that could impact existing apps.