OnDataChanged is never called

后端 未结 1 1970
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-21 13:37

I am trying the dataitem APi and here is my code

mGoogleApiClient = new GoogleApiClient.Builder(this)
            .addConnectionCallbacks(new GoogleApiClient.Co         


        
1条回答
  •  攒了一身酷
    2021-01-21 14:08

    If you are using DataApi.DataListener, then you have to addListener after GoogleApiClient connected. Something like: Wearable.DataApi.addListener(mGoogleApiClient, this) inside your GoogleApiClient.ConnectionCallbacks.

    If you are using WearableListenerService make sure you have similar code in your AndroidManifest.xml on the receiving/listening side as shown below:

    
        
            
                
                      android:pathPrefix="/YourDataMapPathPrefix"/>
            
    
    

    Also keep in mind that onDataChanged will get call only if the data is ACTUALLY changed. Let's said that the old data is ("Person", "Bob") and you replace it with same data ("Person", "Bob"), then onDataChanged will not get triggered since the data does not change in fact. But onDataChanged will get triggered if you put ("Person", "Bob2") instead.

    0 讨论(0)
提交回复
热议问题