【问题标题】:The interval of results from Google's activity recognition isn't regularGoogle 活动识别的结果间隔不规律
【发布时间】:2023-03-11 04:33:01
【问题描述】:

我正在研究谷歌的活动识别,最后我从这项服务中得到了结果。

但是,requestActivityUpdates(long detectionIntervalMillis, PendingIntent callbackIntent) 函数似乎无法正常工作。检测间隔不规律,当我当前的活动发生变化时会减少到 30~50 秒。它不像 google I/O 2013 上的现场演示(Google I/O 2013 Location API,从 27:47 到 28:45)。有人对此有同样的问题吗?

【问题讨论】:

  • 我现在遇到了这个问题,活动更新的传递速度比detectionIntervalMillis 慢,尤其是当活动发生变化时,即使我设置了detectionIntervalMillis = 0

标签: android intervals activity-recognition


【解决方案1】:

这有点令人困惑,但变量 long detectionIntervalMillis 并没有固定间隔 - 它设置了两次更新之间的最大间隔。

正如官方文档中所说:

如果另一个应用程序也以更快的速度请求活动更新,则可能比detectionIntervalMillis 参数更频繁地接收活动。当活动检测服务接收到当前活动可能发生变化的信号时,它也可以更快地接收更新,例如如果设备长时间静止然后从手机充电器上拔下。

Documentation

【讨论】:

  • 问题更多是关于为什么活动识别比detectionIntervalMillis
【解决方案2】:

不要直接在 onCreate 上添加 build() 部分,而是尝试添加下面的方法并在 onCreate() 上调用它。并尝试从google sample 跟踪代码,我从该示例中删除了代码。

protected synchronized void buildGoogleApiClient() {
    mGoogleApiClient = new GoogleApiClient.Builder(this)
            .addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this)
            .addApi(ActivityRecognition.API)
            .build();
}

并将buildGoogleApiClient() 添加到您的 onCreate 方法中;)这对我很有用!

【讨论】:

    猜你喜欢
    • 2023-04-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-24
    • 1970-01-01
    • 2021-08-02
    • 1970-01-01
    • 2022-01-09
    相关资源
    最近更新 更多