Snapshot API 概览
弃用通知:地点和天气上下文信号
您可以使用 Snapshot API 获取有关用户当前环境的信息。借助 Snapshot API,您可以访问各种情境信号:
- 检测到用户活动,例如他们步行或驾车时。
- 您注册的附近信标。
- 耳机状态,是否已插上。
- 位置,包括纬度和经度。
系统会缓存这些值,以便快速返回。如果没有数据,则执行感应和推断以返回最新状态值。Awareness API 会返回具有公共 API 的上下文类型的现有数据类型。
每个上下文信号都有一个对应的 Snapshot API 方法。例如,如需获取当前检测到的 activity,请调用 getDetectedActivity()
,使用 SuccessListener
获取 DetectedActivityResponse
,然后调用 getActivityRecognitionResult()
以返回 ActivityRecognitionResult
,您可以从中获取实际的请求数据。
以下示例展示了如何获取最新检测到的活动:
Awareness.getSnapshotClient(this).getDetectedActivity()
.addOnSuccessListener(new OnSuccessListener<DetectedActivityResponse>() {
@Override
public void onSuccess(DetectedActivityResponse dar) {
ActivityRecognitionResult arr = dar.getActivityRecognitionResult();
}
})
如需详细了解如何处理请求数据,请参阅获取快照数据。
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2023-09-14。
[null,null,["最后更新时间 (UTC):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."]]],[]]