EyeQ Tech
EyeQ Tech

Reputation: 7358

WearableListenerService, onDataChanged() is not called

I followed the tutorial to invoke a Wearable activity from phone, posted here How to send notification from handheld to wear to open Activity on wear device. However, I grab the source code from the answer. However, I couldn't get it running. It looks like onDataChanged() is never called. I ask this as a question on its own because it seems the example works for others. I'm on KitKat 4.4.2, if that matters.

Any tip where to check, thanks.

Upvotes: 18

Views: 9762

Answers (7)

richard
richard

Reputation: 854

make sure that the applicationId in the build.gradle file ist the same for your handheld and your wearable module

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"

    defaultConfig {
        applicationId "your.applicationid" // needs to be the same in both modules
        minSdkVersion 20
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
        targetCompatibility = '1.7'
}

...

Upvotes: 6

Gökhan Kurt
Gökhan Kurt

Reputation: 531

If you are using Android Wear emulator than be sure that Android Wear app on the phone has Connected to the emulator and you run adb tcp forwarding command.

Additional details here: https://stackoverflow.com/a/25506889/1044864

Upvotes: 0

Marc
Marc

Reputation: 1184

With version 8.3.0 of the Play Services the messages could be delayed up to 30 minutes. With the new setUrgent() method it is send without a delay.

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.

http://android-developers.blogspot.nl/2015/11/whats-new-in-google-play-services-83.html

Upvotes: 16

Dorin
Dorin

Reputation: 57

1.check build.gradle for mobile and for wear to have the same play version compile 'com.google.android.gms:play-services-wearable:6.5.87'

Mine has a + sign on mobile and it took the last version on mobile only

Upgrade same version on both until it works

2.Stupid workaround, if nothing works (!! this works with different play versions on pairs, if you do step one you do not need this)

....
Wearable.DataApi.putDataItem(mGoogleApiClient, request)
.......  
this line after your put

Wearable.DataApi.deleteDataItems(mGoogleApiClient, request.getUri());

It is a replication trick that do 3 things :

  • wake up pair

  • send data

  • execute OnDataChange on both with good data

  • delete data (execute OnDataChange on both with no data) (so prepare to work even after the data was deleted)

My problem was that data was queued and paused on watch until first touch - now it is real time bidirectional

Upvotes: 3

Alexander Sommer
Alexander Sommer

Reputation: 1

after onDataChanged method, I am forcing

onDataChanged(DataEventBuffer dataEvents) {

--doDataStuff---

mGoogleApiClient.disconnect(); mGoogleApiClient.connect();

}

only with this setting the onDataChanged is working for me.

Upvotes: -2

corazza
corazza

Reputation: 32364

For me, the culprit was this line in the service declaration:

android:permission="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE"

I'm not exactly sure what about this line causes the service not to receive events, but when it was removed it started functioning properly.

Upvotes: 2

Tom
Tom

Reputation: 5068

There are two things you can check:

  • packageName of the wear app should be identical to packageName of the device app
  • onDataChanged() gets only called when the data really changes. If you put the same data into the DataApi multiple times, the method is only called once until you write different data. You could add a timestamp to the data to make sure that the method gets called once for each write operation. However, using the DataApi is potentially more expensive in terms of battery usage than sending a message. So if you just want to trigger an action after putting data into the DataApi, simply send a message when you are done.

Upvotes: 51

Related Questions