Android M Developer Preview - API Preview(一)

來源:互聯網
上載者:User

標籤:

API Overview

The M Developer Preview gives you an advance look at the upcoming release for the Android platform, which offers new features for users and app developers. This document provides an introduction to the most notable APIs.

即將到來的Android平台的釋放版本將會為使用者以及App開發人員提供新的功能特性,M Developer Preview則為此提供一個預覽。本文檔將會向大家介紹大多數值得注意的APIs。

 

The M Developer Preview is intended for developer early adopters and testers. If you are interested in influencing the direction of the Android framework, give the M Developer Preview a try and send us your feedback!

M Developer Preview面向前期的開發人員和測試人員。如果你有意直接作用於Android frameword,不妨嘗試下M Developer Preview,並向我們發送你的反饋!

 

Caution: Do not publish apps that use the M Developer Preview to the Google Play store.

警告:不要推送那些使用了M Developer Preview的應用到Google市集上去。

 

Note: This document often refers to classes and methods that do not yet have reference material available on developer.android.com. These API elements are formatted in code style in this document (without hyperlinks). For the preliminary API documentation for these elements, download the preview reference.

注意:本文檔會經常提到在developer.android.com上還沒有對應的可用參考材料的類和方法。本文檔中這些API標記都是代碼樣式的格式(而不是超連結)。這些標籤對應的早期的API文檔,在preview reference中可以下載。

 

Important behavior changes重要的行為更改

If you have previously published an app for Android, be aware that your app might be affected by changes in the platform.

如果你之前已經推送了一款Android平台下的App,你會發覺你的App可能會受到新平台中行為的更改而帶來的影響。

 

Please see Behavior Changes for complete information.

請閱讀行為更改章節擷取完整的資訊。

 

App Linking App 連結

This preview enhances Android’s intent system by providing more powerful app linking. This feature allows you to associate an app with a web domain you own. Based on this association, the platform can determine the default app to use to handle a particular web link and skip prompting users to select an app. To learn how to implement this feature, see App Linking.

該預覽通過提供更多有效App連結改善了Android的意圖系統。該特性允許你通過你自己的一個web網域名稱來關聯某個app。在此關聯的基礎上,新平台會確定用於處理某一特定web連結的預設App,並跳過提示使用者選擇一款App的步驟。查閱App Linking,以學習如何?該特性。

 

Auto Backup for Apps Apps自動備份

The system now performs automatic full data backup and restore for apps. For the duration of the M Developer Preview program, all apps are backed up, independent of which SDK version they target. After the final M SDK release, your app must target M to enable this behavior; you do not need to add any additional code. If users delete their Google accounts, their backup data is deleted as well. To learn how this feature works and how to configure what to back up on the file system, see Auto Backup for Apps.

現在的Android系統平台會自動地對App進行所有資料的備份與還原。M Developer Preview 程式運行期間,所有的App都會被備份,且與各個App的目標SDK版本無關。M SDK最終的預覽版釋放之後,你的App必須target到M以啟用該行為;無須添加任何額外的代碼。如果使用者刪除了他們的Google賬戶,他們的資料備份也會被刪除。學習該特性的工作原理及如何設定將被被備份到檔案系統上的資料,請查看Auto Backup for Apps。

Authentication 身分識別驗證

This preview offers new APIs to let you authenticate users by using their fingerprint scans on supported devices, and check how recently the user was last authenticated using a device unlocking mechanism (such as a lockscreen password). Use these APIs in conjunction with the Android Keystore system.

為了能夠讓你在支援指紋識別的裝置上通過指紋掃描來進行使用者身分識別驗證,同時檢查最近一次進行身分識別驗證的使用者是如何使用裝置解鎖機制的(例如鎖屏密碼),該預覽版提供了一些新的APIs,結合Android Keystore system章節來使用這些API吧。

 

Fingerprint Authentication 指紋認證

To authenticate users via fingerprint scan, get an instance of the new FingerprintManager class and call the authenticate() method. Your app must be running on a compatible device with a fingerprint sensor. You must implement the user interface for the fingerprint authentication flow on your app, and use the standard Android fingerprint icon in your UI. The Android fingerprint icon (c_fp_40px.png) is included in the sample app. If you are developing multiple apps that use fingerprint authentication, note that each app must authenticate the user’s fingerprint independently.

為了通過指紋掃描進行使用者身分識別驗證,需擷取新類FingerprintManager的一個執行個體並調用方法authenticate()。你的應用程式必須運行在一個相容指紋感應器的裝置上。在你的App上你必須為指紋認證流程實現一個使用者介面,並且在應用UI中使用標準的Android指紋認證表徵圖。Android指紋認證表徵圖(c_fp_40px.png)包含在樣本程式中。如果你正開發多個使用指紋認證的應用程式,需要注意每一個應用都必須獨立地驗證使用者的指紋。

 

To use this feature in your app, first add the USE_FINGERPRINT permission in your manifest.

為了在你的App中使用該特性,首先需要在你的清單設定檔manifest中添加USE_FINGERPRINT許可權:

<uses-permission  android:name="android.permission.USE_FINGERPRINT" />

 

To see an app implementation of fingerprint authentication, refer to the Fingerprint Dialog sample. For a demonstration of how you can use these authentication APIs in conjunction with other Android APIs, see the video Fingerprint and Payment APIs.

如要查看一個指紋認證的應用程式實現,請查閱Fingerprint Dialog sample.視頻Fingerprint and Payment APIs,示範了如何結合使用這些身分識別驗證APIs以及其他的Android APIs。

 

If you are testing this feature, follow these steps:

如果你正在測試該特性,那麼跟隨如下步驟:

  1. Install Android SDK Tools Revision 24.3, if you have not done so.

先安裝Android SDK Tools Revision 24.3,如果你還沒有完成這一步的話。

  1. Enroll a new fingerprint in the emulator by going to Settings > Security > Fingerprint, then follow the enrollment instructions.

在模擬器中依次點擊設定>安全>指紋以添加一個新的指紋,之後按照指紋登記指南來做即可。

  1. Use an emulator to emulate fingerprint touch events with the following command. Use the same command to emulate fingerprint touch events on the lockscreen or in your app.

使用一個模擬器及如下命令來類比指紋觸摸事件。使用同樣的命令在螢幕上面或者在你的應用程式中類比指紋觸摸事件。

adb -e emu finger touch <finger_id>

On Windows, you may have to run telnet 127.0.0.1

在Windows系統上,你可能需要運行如下命令:telnet 127.0.0.1

<emulator-id> followed by finger touch <finger_id>.

<emulator-id>緊跟finger touch <finger_id>之後。

Confirm Credential 確認憑證

Your app can authenticate users based on how recently they last unlocked their device. This feature frees users from having to remember additional app-specific passwords, and avoids the need for you to implement your own authentication user interface. Your app should use this feature in conjunction with a public or secret key implementation for user authentication.

你的應用程式可以基於使用者最近一次解鎖其裝置的方式來進行使用者身分識別驗證。該特性使使用者從不得不記住額外的特定於應用程式的密碼中解脫出來,同時也避免了你來實現自己的使用者身分識別驗證介面的必要。對於使用者身分識別驗證而言,你的應用程式應該將該特性同一個公開的或者私密的密鑰實現一塊協同使用。

To set the timeout duration for which the same key can be re-used after a user is successfully authenticated, call the new setUserAuthenticationValidityDurationSeconds() method when you set up a KeyGenerator or KeyPairGenerator.

為了設定相同的Key在某個使用者成功進行身分識別驗證之後的逾時時間,當你搭建一個KeyGenerator或者KeyPairGenerator時調用新方法setUserAuthenticationValidityDurationSeconds()

Avoid showing the re-authentication dialog excessively -- your apps should try using the cryptographic object first and if the the timeout expires, use the createConfirmDeviceCredentialIntent() method to re-authenticate the user within your app.

為了避免重新驗證身份對話方塊的過度顯示,首先你的應用程式應當儘可能的使用加密對象,如果逾時失效了,使用createConfirmDeviceCredentialIntent()方法以在你的應用程式中重新驗證使用者身份。

To see an app implementation of this feature, refer to the Confirm Credential sample。

查看該特性的應用程式實現,請查閱Confirm Credential sample。

Direct Share 直接分享

This preview provides you with APIs to make sharing intuitive and quick for users. You can now define direct share targets that launch a specific activity in your app. These direct share targets are exposed to users via the Share menu. This feature allows users to share content to targets, such as contacts, within other apps. For example, the direct share target might launch an activity in another social network app, which lets the user share content directly to a specific friend or community in that app.

該預覽會向你提供一些讓分享對使用者而言更直觀快速的APIs。現在你可以定義直接分享組件,以在你的App中啟動某個特定的activity。這些直接分享組件會通過分享菜單暴露給使用者。該特性允許使用者在其它應用程式中分享特定內容到targets,諸如連絡人等。例如,直接分享組件可以啟動其它社交網路類App中的某個activity,這將讓使用者能夠在這些應用程式中直接分享特定內容到某個特定的朋友或者社區中。

To enable direct share targets you must define a class that extends the ChooserTargetService class. Declare your service in the manifest. Within that declaration, specify the BIND_CHOOSER_TARGET_SERVICE permission and an intent filter using the SERVICE_INTERFACE action.

為了啟用直接分享組件,你必須定義一個繼承自ChooserTargetService的類。在資訊清單檔manifest中定義你的服務。在該定義中,指定BIND_CHOOSER_TARGET_SERVICE許可權和一個使用BIND_CHOOSER_TARGET_SERVICE動作的意圖過濾器。

The following example shows how you might declare the ChooserTargetService in your manifest.

如下樣本展示了如何在資訊清單檔中定義ChooserTargetService.

<service android:name=".ChooserTargetService"
android:label="@string/service_name"
android:permission="android.permission.BIND_CHOOSER_TARGET_SERVICE">
 <intent-filter>
  <action
android:name="android.service.chooser.ChooserTargetService"/>
 </intent-filter>
</service>

For each activity that you want to expose to ChooserTargetService, add a <meta-data> element with the name "android.service.chooser.chooser_target_service" in your app manifest.

對於每個你想要暴露給ChooserTargetService的activity,在你的資訊清單檔中添加一個使用name為"android.service.chooser.chooser_target_service"的<meta-data>標籤。

<activity android:name=".MyShareActivity”
        android:label="@string/share_activity_label">
 <intent-filter>
        <action android:name="android.intent.action.SEND" />
 </intent-filter>
  <meta-data
     android:name="android.service.chooser.chooser_target_service"
     android:value=".ChooserTargetService" />
</activity>
Voice Interactions 語音互動

This preview provides a new voice interaction API which, together with Voice Actions, allows you to build conversational voice experiences into your apps. Call the isVoiceInteraction() method to determine if a voice action triggered your activity. If so, your app can use the VoiceInteractor class to request a voice confirmation from the user, select from a list of options, and more.

該預覽提供了一個新的語音互動API,與Voice Actions相同,允許你在應用程式中構建對話式語音體驗。調用方法isVoiceInteraction()以確定你的activity是否觸發了一個語音活動。如果是,你的應用程式可以使用類VoiceInteractor向使用者請求語音確認,選擇一系列選項,等等。

Most voice interactions originate from a user voice action. A voice interaction activity can also, however, start without user input. For example, another app launched through a voice interaction can also send an intent to launch a voice interaction. To determine if your activity launched from a user voice query or from another voice interaction app, call the isVoiceInteractionRoot() method. If another app launched your activity, the method returns false. Your app may then prompt the user to confirm that they intended this action.

多數的語音互動來源於一個使用者的語音活動。一個語音互動activity也可以這樣,然而,無需使用者輸入。比如,另一個通過某個語音互動啟動的應用程式也可以發送一個意圖來啟動一個語音互動。調用方法isVoiceInteractionRoot()以確定你的activity是否被某個使用者語音查詢或者其他語音互動App啟動了。如果另一個App啟動了你的activity,該方法會返回false。你的App之後可以提示使用者以確認他們對該活動的打算。

To learn more about implementing voice actions, see the Voice Actions developer site.

查看章節Voice Actions developer site以更多的瞭解語音活動實現。

Assist API 輔助的API

This preview offers a new way for users to engage with your apps through an assistant. To use this feature, the user must enable the assistant to use the current context. Once enabled, the user can summon the assistant within any app, by long-pressing on the Home button.

該預覽為使用者提供了一種,通過一個助手同你的App互動,的新方式。為了使用該特性,使用者必須啟用使用當前上下文起用該助手。一旦啟用,使用者可以在任何App中喚起該助手,通過長按住Home按鈕即可。

 

To provide the assistant with additional context from your app, follow these steps:

按照如下步驟,即可使用應用程式的附加上下文來添加該助手。

  1. Implement the Application.OnProvideAssistDataListener interface.

實現介面Application.OnProvideAssistDataListener

  1. Register this listener by using registerOnProvideAssistDataListener().

使用registerOnProvideAssistDataListener()方法註冊該監聽器。

  1. In order to provide activity-specific contextual information, override the onProvideAssistData() callback and, optionally, the new onProvideAssistContent() callback.

為了能夠提供特定於activity的上下文關聯的資訊,重寫回呼函數onProvideAssistData()並有選擇性地重寫新的回呼函數onProvideAssistContent()

 

Notifications 通知

This preview adds the following API changes for notifications:

該預覽對通知添加了如下的API更改:

  • New INTERRUPTION_FILTER_ALARMS filter level that corresponds to the new Alarms only do not disturb mode.

新的INTERRUPTION_FILTER_ALARMS過濾器層級以符合新的Alarms only請勿打擾模式。

  • New CATEGORY_REMINDER category value that is used to distinguish user-scheduled reminders from other events (CATEGORY_EVENT) and alarms (CATEGORY_ALARM).

新的CATEGORY_REMINDER類型值,用於區分使用者定時提醒與其他的事件(CATEGORY_EVENT)及鬧鐘(CATEGORY_EVENT)。

  • New Icon class that you can attach to your notifications via the setSmallIcon() and setLargeIcon() methods. Similarly, the addAction() method now accepts an Icon object instead of a drawable resource ID.

新的Icon類,可以通過方法setSmallIcon()和方法setSmallIcon()將該類與通知相關聯。

  • New getActiveNotifications() method that allows your apps to find out which of their notifications are currently alive. To see an app implementation that uses this feature, see the Active Notifications sample

新的方法getActiveNotifications(),允許你的應用程式找出在所有通知中當前活動的通知。查閱Active Notifications sample以查看該特性使用的應用程式實現。

Bluetooth Stylus Support  藍芽手寫筆支援

This preview provides improved support for user input using a Bluetooth stylus. Users can pair and connect a compatible Bluetooth stylus with their phone or tablet. While connected, position information from the touch screen is fused with pressure and button information from the stylus to provide a greater range of expression than with the touch screen alone. Your app can listen for stylus button presses and perform secondary actions, by registering View.OnContextClickListener and GestureDetector.OnContextClickListener objects in your activity.

該預覽對使用了一個藍芽手寫筆的使用者輸入提供了一個改進的支援。使用者可以匹配並串連一個相容的藍芽手寫筆和他們的手機或者平板。當串連之後,通過螢幕觸摸產生的位置資訊會轉為壓力,同時通過手寫筆產生的按鈕資訊相比僅僅觸控螢幕幕而言會提供一個更大的表述範圍。通過在activity中註冊View.OnContextClickListenerView.OnContextClickListener對象,你的應用程式可以監聽手寫筆的按鈕及壓力,執行次要動作。

Use the MotionEvent methods and constants to detect stylus button interactions:

使用MotionEvent類中的方法和變數來檢測手寫筆按鈕活動:

If the user touches a stylus with a button on the screen of your app, the getTooltype() method returns TOOL_TYPE_STYLUS.

如果使用者通過應用程式螢幕上的一個按鈕觸摸了一個手寫筆,方法getTooltype()會返回getTooltype()

For apps targeting M Preview, the getButtonState() method returns BUTTON_STYLUS_PRIMARY when the user presses the primary stylus button. If the stylus has a second button, the same method returns BUTTON_STYLUS_SECONDARY when the user presses it. If the user presses both buttons simultaneously, the method returns both values OR‘ed together (BUTTON_STYLUS_PRIMARY|BUTTON_STYLUS_SECONDARY).

對於以M Preview為目標系統的應用程式而言,當使用者按下主要的手寫筆按鈕時方法getButtonState()會返回BUTTON_STYLUS_PRIMARY。如果手寫筆有第二個按鈕,當使用者按下該按鈕時該方法會返回BUTTON_STYLUS_SECONDARY。如果使用者同事按下了兩個按鈕的話,該方法會同時返回這兩個值相互或運算之後的值(BUTTON_STYLUS_PRIMARY|BUTTON_STYLUS_SECONDARY)。

 

Android M Developer Preview - API Preview(一)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.