Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 921
EyeQ Tech Avatar asked Aug 05 '14 14:08

EyeQ Tech


3 Answers

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.
like image 72
Tom Avatar answered Nov 19 '22 23:11

Tom


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

like image 16
Marc Avatar answered Nov 19 '22 23:11

Marc


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'
}

...
like image 6
richard Avatar answered Nov 19 '22 23:11

richard