Skip to content

Most visited

Recently visited


Code Samples

Use the code samples below to learn about Android O capabilities and APIs. To download the samples in Android Studio, select the File > New > Import Samples menu option.

Note: These downloadable projects are designed for use with Gradle and Android Studio.

Background Execution Limits

Bluetooth Advertisements Sample - The Bluetooth Advertisements sample was updated to comply with Android O's background execution limits. The sample previously created a background service which was used to broadcast Bluetooth LE Advertisements; this process is now started as a foreground service to ensure execution.

Get it on GitHub

Background Location Restrictions

LocationUpdatesPendingIntent Sample - Shows how to request location updates using a PendingIntent. For apps targeting Android 7.0 but running on Android O, developers can use either PendingIntent.getService() or PendingIntent.getBroadcast(). For apps targeting Android O, PendingIntent.getService() does not work due to the limits placed on services started in the background. When targeting Android O, developers should use PendingIntent.getBroadcast().

Get it on GitHub

LocationUpdatesForegroundService Sample - Shows how to use a foreground service to get location updates when the app activities are not visible. For apps running on Android O (even apps that target Android 7.0 (API level 24) or lower), background updates are limited to only a few times per hour. Using a foreground service is a way to receive more frequent updates.

Get it on GitHub

Notification Channels

NotificationChannels Sample - Android O adds support for notification channels, apps to organize their notifications into topical categories. Each category can have its own alert style, and users are able to selectively enable or disable categories to match their interests. This sample demonstrates how to create channels and appropriately annotate notifications.

Get it on GitHub

Autofill Framework

AutofillFramework Sample - This sample demonstrates the use of the Autofill Framework introduce in Android O. It includes implementations of client Activities that want to be autofilled, and a Service that can provide autofill data to those Activities.

Get it on GitHub

Picture-in-Picture Mode

PictureInPicture Sample - This sample demonstrates basic usage of Picture-in-Picture mode for handheld devices. The sample plays a video. The video keeps on playing when the app is turned into Picture-in-Picture mode. On Picture-in-Picture screen, the app shows an action item to pause or resume the video.

Get it on GitHub


AAudio Echo Sample - AAudio is a new NDK API that gives Pro Audio apps access to low-latency audio on supported devices. This sample demonstrates how to create an input and output stream, configured for loopback.

Get it on GitHub

This site uses cookies to store your preferences for site-specific language and display options.


This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.

Take a one-minute survey?
Help us improve Android tools and documentation.