Sử dụng bộ sưu tập để sắp xếp ngăn nắp các trang
Lưu và phân loại nội dung dựa trên lựa chọn ưu tiên của bạn.
Với Google Awareness API, bạn có thể cho phép ứng dụng của mình phản ứng một cách thông minh với tình huống hiện tại của người dùng. Awareness API cung cấp 5 loại bối cảnh khác nhau, bao gồm cả hoạt động của người dùng và các đèn hiệu ở gần. Những loại này cho phép ứng dụng của bạn cải thiện trải nghiệm người dùng theo những cách mới mà trước đây không thể thực hiện được. Ứng dụng của bạn có thể kết hợp các tín hiệu ngữ cảnh này để suy luận về tình huống hiện tại của người dùng và sử dụng thông tin này để cung cấp trải nghiệm tuỳ chỉnh, chẳng hạn như đề xuất danh sách phát khi người dùng cắm tai nghe và bắt đầu chạy bộ.
Lợi ích của Awareness API
Awareness API mang lại một số lợi ích:
Dễ dàng triển khai: Bạn chỉ cần thêm một API duy nhất vào ứng dụng của mình, điều này giúp đơn giản hoá đáng kể quá trình tích hợp và cải thiện năng suất.
Dữ liệu ngữ cảnh tốt hơn: Các tín hiệu thô được xử lý để cải thiện chất lượng. Ví dụ: các thuật toán nâng cao được dùng để xác định hoạt động của người dùng với độ chính xác cao.
Tình trạng hệ thống tối ưu: Awareness API tự động quản lý tác động của API này đến thời lượng pin và mức sử dụng dữ liệu để ứng dụng của bạn không phải làm việc này.
Hàng rào và ảnh chụp nhanh
Awareness API bao gồm 2 API riêng biệt mà ứng dụng của bạn có thể dùng để nhận tín hiệu ngữ cảnh nhằm xác định tình huống hiện tại của người dùng:
Fence API: API này cho phép ứng dụng của bạn phản ứng với tình huống hiện tại của người dùng và cung cấp thông báo khi một tổ hợp các điều kiện theo bối cảnh được đáp ứng. Ví dụ: bất cứ khi nào người dùng đi bộ và cắm tai nghe. Sau khi bạn đăng ký một hàng rào, Fence API có thể gửi lệnh gọi lại đến ứng dụng của bạn ngay cả khi ứng dụng đó không chạy.
Snapshot API: API này cho phép ứng dụng của bạn yêu cầu thông tin về bối cảnh hiện tại của người dùng, chẳng hạn như vị trí hiện tại của người dùng và điều kiện thời tiết hiện tại.
Loại ngữ cảnh
Ngữ cảnh là yếu tố cốt lõi của Awareness API. Dữ liệu theo ngữ cảnh bao gồm dữ liệu từ cảm biến, chẳng hạn như vị trí (vĩ độ và kinh độ), loại địa điểm (chẳng hạn như công viên hoặc quán cà phê) và hoạt động (chẳng hạn như đi bộ hoặc lái xe). Bạn có thể kết hợp các loại cơ bản này (hoặc tín hiệu) để suy đoán tình huống của người dùng một cách chi tiết hơn. Mở rộng thông báo sau để xem những tín hiệu theo ngữ cảnh đã bị ngừng sử dụng.
Thông báo ngừng sử dụng: Tín hiệu theo bối cảnh về Địa điểm và Thời tiết
Bảng sau đây mô tả các loại bối cảnh cơ bản mà Awareness API hiện cung cấp:
Loại ngữ cảnh
Ví dụ:
Thời gian
Giờ địa phương hiện tại
Thông tin vị trí
Vĩ độ và kinh độ
Hoạt động
Hoạt động của người dùng được phát hiện, chẳng hạn như đi bộ, chạy bộ hoặc đạp xe
Đèn hiệu
Các thiết bị báo hiệu lân cận khớp với không gian tên đã chỉ định
Tai nghe
Trạng thái cho biết tai nghe có được cắm vào hay không
[[["Dễ hiểu","easyToUnderstand","thumb-up"],["Giúp tôi giải quyết được vấn đề","solvedMyProblem","thumb-up"],["Khác","otherUp","thumb-up"]],[["Thiếu thông tin tôi cần","missingTheInformationINeed","thumb-down"],["Quá phức tạp/quá nhiều bước","tooComplicatedTooManySteps","thumb-down"],["Đã lỗi thời","outOfDate","thumb-down"],["Vấn đề về bản dịch","translationIssue","thumb-down"],["Vấn đề về mẫu/mã","samplesCodeIssue","thumb-down"],["Khác","otherDown","thumb-down"]],["Cập nhật lần gần đây nhất: 2025-09-05 UTC."],[[["\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 |"]]