什麼是 Awareness API?
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
透過 Google Awareness API,您可以讓應用程式根據使用者目前的情況做出智慧型回應。Awareness API 會公開五種不同的情境類型,包括使用者活動和附近的訊號發射器。這類類型可讓應用程式以先前無法實現的新方式,改善使用者體驗。應用程式可以結合這些背景信號,推斷使用者的目前情況,並利用這些資訊提供客製化體驗,例如在使用者插入耳機並開始慢跑時,提供播放清單建議。
Awareness API 的優點
Awareness API 提供以下多項優點:
- 輕鬆實作:您只需在應用程式中新增單一 API,即可大幅簡化整合作業並提高工作效率。
- 更優質的內容資料:系統會處理原始信號,提升品質。舉例來說,系統會使用進階演算法,以高準確度判斷使用者的活動。
- 最佳系統健康狀態:Awareness API 會自動管理對電池續航力和資料用量造成的影響,因此應用程式不必自行管理。
柵欄和快照
Awareness API 包含兩個不同的 API,可讓應用程式取得情境信號,進而判斷使用者的目前情況:
- Fence API:這個 API 可讓應用程式回應使用者的目前情況,並在符合多個背景條件時提供通知。舉例來說,當使用者在散步時插入耳機,註冊邊界後,即使應用程式未執行,Fence API 仍可傳送回呼。
- Snapshot API:這個 API 可讓應用程式要求使用者目前情境的相關資訊,例如使用者目前的位置和目前天氣狀況。
環境類型
Aware API 的核心是背景資訊。情境資料包括感應器衍生資料,例如位置 (經緯度)、地點類型 (例如公園或咖啡廳) 和活動 (例如步行或開車)。這些基本類型或信號可相互搭配,進一步推斷使用者的具體情況。展開以下通知,查看哪些比對內容訊號已淘汰。
下表說明 Awareness API 目前提供的基本情境類型:
結構定義類型 |
範例 |
時間 |
目前的當地時間 |
位置 |
經緯度 |
活動 |
偵測到使用者活動,例如步行、跑步或騎單車 |
信標 |
符合指定命名空間的附近信標 |
耳罩式耳機 |
耳機是否已插入的狀態 |
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-08-31 (世界標準時間)。
[null,null,["上次更新時間:2025-08-31 (世界標準時間)。"],[[["\u003cp\u003eThe Google Awareness API lets your app intelligently respond to the user's context, such as their activity, location, and nearby beacons.\u003c/p\u003e\n"],["\u003cp\u003eIt offers benefits like easy implementation, improved context data quality, and automatic management of system resources.\u003c/p\u003e\n"],["\u003cp\u003eThe API provides two ways to access context: the Fence API for reacting to situations and the Snapshot API for requesting current information.\u003c/p\u003e\n"],["\u003cp\u003eSupported context types include time, location, activity, beacons, and headphone status, while places and weather signals are deprecated.\u003c/p\u003e\n"]]],[],null,["# What's the Awareness API?\n\nWith the Google Awareness API, you can enable your app to intelligently react to the\nuser's current situation. The Awareness API exposes five different\n[context types](#context-types), which include user activity,\nand nearby beacons. These types enable your app to refine the user experience in\nnew ways that weren't possible before. Your app can combine these context\nsignals to make inferences about the user's current situation, and use this\ninformation to provide customized experiences, such as a playlist suggestion\nwhen the user plugs in their headphones and starts to jog.\n\nAwareness API benefits\n----------------------\n\nThe Awareness API provides several benefits:\n\n- **Ease of implementation:** You only need to add a single API to your app, which greatly simplifies integration and improves your productivity.\n- **Better context data:** Raw signals are processed for improved quality. For example, advanced algorithms are used to determine the user's activity with a high level of accuracy.\n- **Optimal system health:** The Awareness API automatically manages its impact on battery life and data usage so that your app doesn't have to.\n\nFences and snapshots\n--------------------\n\nThe Awareness API consists of two distinct APIs that your app can use to\nget context signals in order to determine the user's current situation:\n\n- [**Fence API:**](/awareness/android-api/fence-api-overview) This API lets your app react to the user's current situation, and provides notification when a combination of context conditions are met. For example, whenever the user takes a walk and their headphones are plugged in. Once a fence is registered, the Fence API can send callbacks to your app even when it's not running.\n- [**Snapshot API:**](/awareness/android-api/snapshot-api-overview) This API lets your app request information about the user's current context, such as the user's current location and the current weather conditions.\n\nContext types\n-------------\n\nContext is at the heart of the Awareness API. Contextual data includes\nsensor-derived data such as location (latitude and longitude), place type,\nlike a park or coffee shop, and activity, such as a walk or drive. These basic\ntypes, or signals, can be combined to extrapolate the user's situation in more\nspecific detail. Expand the following notice to see which contextual signals\nhave been deprecated.\n**Deprecation notice: Places and Weather contextual signals** **Warning:**\n| The Places and Weather contextual signals, exposed by the\n| [`getPlaces()`](/android/reference/com/google/android/gms/awareness/SnapshotClient#getPlaces()), and\n| [`getWeather()`](/android/reference/com/google/android/gms/awareness/SnapshotClient#getWeather())\n| methods, were deprecated.\n|\n| - The Places contextual signal was turned off. Continued use of this signal was restricted to customers with existing implementations, through October 30, 2019. New implementations must use the [Places SDK for Android](/places/android-sdk) instead of the Places contextual signal.\n| - The Weather contextual signal has also been turned off. Continued use of this signal has been restricted to customers with existing implementations, through January 31, 2020. Google doesn't offer alternative functionality for the Weather contextual signal.\n\nThe following table describes the basic context types currently offered by\nthe Awareness API:\n\n| Context type | Example |\n|--------------|----------------------------------------------------------|\n| Time | Current local time |\n| Location | Latitude and longitude |\n| Activity | Detected user activity, like walking, running, or biking |\n| Beacons | Nearby beacons that match the specified namespace |\n| Headphones | Status of whether headphones are plugged in, or not |"]]