LoginSignup
11
12

More than 5 years have passed since last update.

Google Play services v8.3のDataApiでデータが直ぐに同期されなくなった

Last updated at Posted at 2015-11-08

11/5 にGoogle Play services 8.3がリリースされました。

このバージョンアップでは、既存のAndroid Wearアプリに影響がある変更がありました。

Finally, if you are developing for wearables, you’ll know that battery life and optimization of power usage are critical in having a great user experience. With Google Play services 8.3, we’ve updated the DataApi to allow for urgency in how data items are synced. Now, a priority can be added to the data item to determine when it should be synced. For example, if you are building an app that requires immediate syncing, such as a remote control app, it can still be done immediately by calling setUrgent(), but for something such as updating your contacts, you could tolerate some delay. Non-urgent DataItems may be delayed for up to 30 minutes, but you can expect that in most cases they will be delivered within a few minutes. Low priority is now the default, so setUrgent() is needed to obtain the previous timing.

ざっとGoogle翻訳してみると、こんな感じでしょうか。
バッテリー持ちを良くするため、DataApiを使って同期するデータのうち優先度が低いものは数分(最大30分)で同期されるようになります。デフォルトでは優先度が低くく設定されるので、すぐに同期して欲しい場合は、setUrgent() を呼ぶ必要がある。

個人的に開発しているAndroid Wear向けのTwitterクライアントでは、すぐにデータが同期されないと困るため修正する必要がありました。

バックグラウンドで同期するようなタイプのアプリでは、数分の遅延は気にならないと思いますので、修正しなくても問題ないと思います(バッテリーにも優しいでしょうし)。

対応方法

対応方法とても簡単で、PutDataRequest.setUrgent() を呼ぶだけです。
(主にスマートフォン側になるかと思います。)

PutDataMapRequest putDataMapRequest = PutDataMapRequest.create(PATH);

// 同期するデータの設定

PutDataRequest request = putDataMapRequest.asPutDataRequest();
// ↓これを呼ぶ!
request.setUrgent();

// データを同期する
Wearable.DataApi.putDataItem(mApiClient, request);

このように1行追加するだけですぐに同期されるようになります。
即時性が求められるアプリで v8.3以上を使用の際にはこの設定を追加するようにしましょう。

11
12
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
11
12