Skip to content Skip to sidebar Skip to footer

Send And Receiving Data Using Datamap - Android Wearable

I am working on an Android Wearable project and I am trying to send data from the mobile device to the Wearable emulator. I am trying log the received data in the wearable but it i

Solution 1:

Sounds like your dataMap is not changing its values, Then it won't send data to the wearable.

You can send Long.toString(System.currentTimeMillis()) to verify that as it changes every time.

Solution 2:

Here are some leads :

  1. On your fifth point, try putting setUrgent() here :

    PutDataRequest putDataReq = putDataMapReq.asPutDataRequest().setUrgent();

Also, if you get a success in the callback, it means your data was sent successfully. It doesn't imply it was received well, or received at well.

  1. Maybe you did, but do you call googleClient.connect() at onStart() or anywhere else ?

  2. onDataChanged() is only called when the data put is really different, if you eep putting the same data, it won't be called. To test, you can add a timestamp to your DataMap.

  3. You need to have the same package names for your mobile and wear applications for them to be able to exchange messages/data.

  4. Maybe you can try implementing a WearableListenerService to receive the data on onDataChanged. The code is not different, it's just that this service is created when data is received, so you don't have to have your app open. Make sure you add the BIND_LISTENER action in this service intent filter on your manifest.

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

Solution 3:

First, try to log the result of putting the DataItem:

Wearable.DataApi.putDataItem(googleClient, putDataReq)
    .setResultCallback(newResultCallback<DataApi.DataItemResult>() {
                @OverridepublicvoidonResult(DataApi.DataItemResult dataItemResult) {
                    Log.d(TAG, "putDataItem status: "
                            + dataItemResult.getStatus().toString());
                }
            });

The dataItemResult.getStatus() call will tell you if something went wrong. Next, make sure you are listening to the onDataChanged() event. On your Wear app onConnected() method, add:

Wearable.DataApi.addListener(googleClient, yourListenerHere);

Finally, to force the data to be sent immediately to the Wear device, use setUrgent():

putDataMapReq = PutDataMapRequest.create("/data").setUrgent();

Hope that helps.

Solution 4:

I finally figured it out. In the watchface side, I declared the Google Api Client instance, mGoogleApiClient, in the WeatherWatchFaceService class as opposed to the Engine class. After I moved it from WeatherWatchFaceService to Engine, the watch side received what I was trying to send from the mobile.

Cheers.

Post a Comment for "Send And Receiving Data Using Datamap - Android Wearable"