WearableListenerService, onDataChanged() is not called

前端 未结 7 932
野趣味
野趣味 2020-12-11 01:05

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

相关标签:
7条回答
  • 2020-12-11 01:20

    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

    0 讨论(0)
  • 2020-12-11 01:22

    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.

    0 讨论(0)
  • 2020-12-11 01:23

    after onDataChanged method, I am forcing

    onDataChanged(DataEventBuffer dataEvents) {

    --doDataStuff---

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

    }

    only with this setting the onDataChanged is working for me.

    0 讨论(0)
  • 2020-12-11 01:24

    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

    0 讨论(0)
  • 2020-12-11 01:25

    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.
    0 讨论(0)
  • 2020-12-11 01:25

    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'
    }
    
    ...
    
    0 讨论(0)
提交回复
热议问题