在运行时更改融合位置优先级

Change Fused Location priority during runtime

我有两个意向服务: 1. 使用 Fused Location API 在后台接收位置更新。 2.在后台接收Activity识别使用Activity识别API.

每当我检测到用户站着不动时,我希望能够将融合位置的优先级从 PRIORITY_HIGH_ACCURACY 更改为 PRIORITY_BALANCED_POWER_ACCURACY。

我听说过 removeLocationUpdates() 然后调用 requestLocationUpdates() 但我不能使用它,因为我只有 运行 意图服务,没有 activity 在后台。

任何帮助都会有所帮助。

您的应用可以同时在多个位置连接到 GoogleApiClient。当您需要时,直接使用 blockingConnect() in your activity recognition IntentService such that you can call requestLocationUpdates() 连接到 GoogleApiClient 会更容易。

注意 requestLocationUpdates() Javadoc 上的注释:

Any previously registered requests that have the same PendingIntent (as defined by equals(Object)) will be replaced by this request.

所以应该不需要调用 removeLocationUpdates().