Android O 8.0新特性(四) 官方Demo



Code Samples 代码示例

Use the code samples below to learn about Android 8.0 (API level 26) 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.

使用下面的代码示例了解Android 8.0(API级别26)功能和API。要在Android Studio中下载示例,请选择文件>新建>导入示例菜单选项。
注意:这些可下载项目专为Gradle和Android Studio使用而设计。


Notification Channels 通知渠道

NotificationChannels Sample - Android 8.0 (API level 26) 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: Java | Kotlin


NotificationChannels示例 - Android 8.0(API级别26)增加了对通知频道的支持,应用程序可将其通知组织到主题类别中。每个类别都可以有自己的警报风格,用户可以选择性地启用或禁用类别以符合他们的兴趣。本示例演示如何创建频道并适当注释通知。
在GitHub上获取它:Java |Kotlin


Autofill Framework 自动填充框架

AutofillFramework Sample - This sample demonstrates the use of the Autofill Framework introduced in Android 8.0 (API level 26). 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: Java | Kotlin

自动填充框架示例 - 此示例演示如何使用Android 8.0(API级别26)中引入的自动填充框架。它包括希望自动填充的客户端活动的实现以及可以向这些活动提供自动填充数据的服务。
在GitHub上获取它:Java |Kotlin


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: Java | Kotlin


PictureInPicture示例 - 此示例演示手持设备的画中画模式的基本用法。该示例播放视频。当应用程序转变为画中画模式时,视频会继续播放。在画中画屏幕上,应用程序会显示一个操作项目以暂停或恢复视频。


Downloadable Fonts 可下载的字体

DownloadableFonts - This sample demonstrates how to use the Downloadable Fonts feature introduced in Android 8.0 (API level 26). Downloadable Fonts allows apps to request a certain font from a provider, instead of bundling it or downloading it themselves. This means there is no need to independently bundle the font as an asset.

Get it on GitHub: Java | Kotlin


DownloadableFonts - 此示例演示如何使用Android 8.0(API级别26)中引入的可下载字体功能。可下载字体允许应用程序从提供者处请求特定字体,而不是捆绑或自行下载。这意味着不需要独立捆绑字体作为资源。


EmojiCompat - This sample demonstrates usage of the Emoji Compatibility Support Library. You can use this library to prevent your app from showing missing emoji characters in the form of tofu (□). You can use either bundled or downloadable emoji fonts. This sample shows both usages.

Get it on GitHub: Java | Kotlin


EmojiCompat - 此示例演示了Emoji Compatibility Support Library的用法。您可以使用此库来防止您的应用程序以豆腐的形式显示缺少表情符号字符(□)。您可以使用捆绑或可下载的表情符号字体。该示例显示了两种用法。
在GitHub上获取它:Java |Kotlin


Background Execution Limits 后台执行限制

Bluetooth Advertisements Sample - The Bluetooth Advertisements sample was updated to comply with Android 8.0 (API level 26)'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: Java

蓝牙广告示例 - Bluetooth广告示例已更新为符合Android 8.0(API级别26)的后台执行限制。该示例先前创建了用于广播蓝牙LE广告的后台服务;此过程现在作为前台服务启动以确保执行。


Background Location Restrictions 后台定位限制

LocationUpdatesPendingIntent Sample - Shows how to request location updates using a PendingIntent. For apps targeting Android 7.x (API levels 24-25) but running on Android 8.0 (API level 26), developers can use either PendingIntent.getService() or PendingIntent.getBroadcast(). For apps targeting Android 8.0, PendingIntent.getService() does not work due to the limits placed on services started in the background. When targeting Android 8.0, developers should use PendingIntent.getBroadcast().

Get it on GitHub: Java


LocationUpdatesPendingIntent示例 - 显示如何使用PendingIntent请求位置更新。对于面向Android 7.x(API级别24-25)但在Android 8.0(API级别26)上运行的应用,开发人员可以使用PendingIntent.getService()或PendingIntent.getBroadcast()。对于面向Android 8.0的应用,PendingIntent.getService()不起作用,因为后台启动的服务受到限制。在定位Android 8.0时,开发者应该使用PendingIntent.getBroadcast()。


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 8.0 (API level 26), 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: Java

LocationUpdatesForegroundService示例 - 显示如何在应用程序活动不可见时使用前台服务获取位置更新。对于在Android 8.0(API级别26)上运行的应用程序,后台更新每小时仅限于几次。使用前台服务是一种接收更频繁更新的方法。


AAudio A音频

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: C++

AAudio Echo Sample - AAudio是一种新的NDK API,可让Pro Audio应用程序访问受支持设备上的低延迟音频。此示例演示如何创建一个输入和输出流,配置为循环回调。(?)
在GitHub上获取它:C ++