Is DataApi reliable and near real time? Extremely delayed

I got the Android Wear app on the market for about 10 months and it stops working (not sure when it stops working).

I am trying to update my downloadable application with some statistics that I record in my mobile application. As I said, this worked perfectly and reliably. I even added a timestamp to this, so it was unique, since onDataChanged is only called if the data has been changed. This guarantees it.

My question

I can send the PutDataMapRequest tag by calling Wearable.DataApi.putDataItem and get a successful callback in my ResultCallback .

onDataChanged usually called at the end, but the delay is too long and longer than before. Moreover, I know that it is configured correctly, because I have an application that I launch, in which I have an Activity , which I launch and receive DataItems , and there is a lag there. I have the same problem with onDataChanged in this Activity .

What I've done

  • Verify that versionCode and versionName match the build.gradle module build.gradle .
  • Make sure the build.gradle files use the same support and google libraries.
  • Make sure both classes connect to GoogleApiClient
  • Make sure the data is different to make it call onDataChanged in the service. I do not need this, but simply in order to make it work.

My code

Mobile

 if (mGoogleApiClient.isConnected()) { PutDataMapRequest putDataMapRequest = PutDataMapRequest.create(path); putDataMapRequest.getDataMap().putString("content", content); putDataMapRequest.getDataMap().putString("title", title); putDataMapRequest.getDataMap().putLong("timestamp", DateTime.now().getMillis()); PutDataRequest request = putDataMapRequest.asPutDataRequest(); Wearable.DataApi.putDataItem(mGoogleApiClient, request) .setResultCallback(new ResultCallback<DataApi.DataItemResult>() { @Override public void onResult(DataApi.DataItemResult dataItemResult) { if (!dataItemResult.getStatus().isSuccess()) { Log.e("WearDevice", "buildWatchOnlyNotification(): Failed to set the data, " + "status: " + dataItemResult.getStatus().getStatusCode()); } else { Log.d(LOG_TAG, "Notificaiton result callback returned successfully: "+dataItemResult.getDataItem().toString());//: "+node.getDisplayName()); } } }); } 

Wear

I have a service that extends WearableListenerService . This is declared in the manifesto as follows.

 <service android:name=".NotificationUpdateService"> <intent-filter> <action android:name="com.google.android.gms.wearable.BIND_LISTENER"/> </intent-filter> </service> 

Here is my service.

 @Override public void onCreate() { super.onCreate(); mGoogleApiClient = new GoogleApiClient.Builder(this) .addApi(Wearable.API) .addConnectionCallbacks(this) .addOnConnectionFailedListener(this) .build(); mGoogleApiClient.connect(); } @Override public int onStartCommand(Intent intent, int flags, int startId) { return super.onStartCommand(intent, flags, startId); } @Override public void onDataChanged(DataEventBuffer dataEvents) { if (MainActivity.DEBUGGING) Log.d(LOG_TAG, "onDataChanged"); for (DataEvent dataEvent : dataEvents) { if (dataEvent.getType() == DataEvent.TYPE_CHANGED) { DataMap dataMap = DataMapItem.fromDataItem(dataEvent.getDataItem()).getDataMap(); String content = dataMap.getString("content"); String title = dataMap.getString("title"); if ("/mydatapath".equals(dataEvent.getDataItem().getUri().getPath())) { buildWearableOnlyNotification(title, content, false); } } } } 

The buildWearableOnlyNotification method creates and runs a pre-notification, and this works fine when it is actually called.

+1
source share
1 answer

Now you need to set the urgency flag if you want your data to be synchronized immediately, otherwise the infrastructure will activate these calls and make them in one call, which means that you can see the delay up to 30 minutes; this is a change made to the most recent Play Services to save battery power when such direct data synchronization is not really needed.

+1
source

Source: https://habr.com/ru/post/1213786/


All Articles