快照 API 總覽
淘汰通知:地點和天氣比對內容訊號
您可以使用 Snapshot API 取得使用者目前環境的相關資訊。透過 Snapshot API,你可以使用各種情境信號:
- 偵測到的使用者活動,例如步行或開車。
- 你註冊的附近信標。
- 耳機狀態:已接上電源。
- 位置,包括緯度和經度。
系統會快取這些值,以便快速傳回。如果沒有任何資料,系統會執行感應和推論作業,以便傳回最新的狀態值。Awareness API 會傳回含有公用 API 的結構定義現有資料類型。
每個內容信號都有對應的 Snapshot API 方法。舉例來說,如要取得目前偵測到的活動,您可以呼叫 getDetectedActivity()
,使用 SuccessListener
取得 DetectedActivityResponse
,然後呼叫 getActivityRecognitionResult()
來傳回 ActivityRecognitionResult
,以便取得實際的要求資料。
以下範例說明如何取得最新的偵測到活動:
Awareness.getSnapshotClient(this).getDetectedActivity()
.addOnSuccessListener(new OnSuccessListener<DetectedActivityResponse>() {
@Override
public void onSuccess(DetectedActivityResponse dar) {
ActivityRecognitionResult arr = dar.getActivityRecognitionResult();
}
})
如要進一步瞭解如何利用要求資料,請參閱取得快照資料。
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2023-09-14 (世界標準時間)。
[null,null,["上次更新時間:2023-09-14 (世界標準時間)。"],[[["The Places and Weather contextual signals within the Awareness API are deprecated and have been turned off, with existing implementations restricted until specified dates."],["Developers should utilize the Places SDK for Android instead of the Places contextual signal for new implementations."],["Google does not offer alternative functionality for the Weather contextual signal, impacting existing implementations relying on it."],["The Awareness API continues to provide other contextual signals through the Snapshot API, including user activity, nearby beacons, headphone state, and location."],["Developers can access these signals using corresponding Snapshot API methods and retrieve relevant data for their applications."]]],[]]