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.
Background Location Restrictions
LocationUpdatesPendingIntent Sample -
Shows how to request location updates using a
apps targeting Android 7.0 but running on Android O, developers can use either
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
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.
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.
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.
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.
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.