OnDataChanged is never called

被刻印的时光 ゝ 提交于 2019-12-01 22:54:47

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:

<service android:name=".YourCustomWearableListenerService">
    <intent-filter>
        <action android:name="com.google.android.gms.wearable.DATA_CHANGED"/>
            <data android:scheme="wear" 
                  android:host="*" 
                  <!-- I believe pathPrefix is optional, removing it will make the service listener to all data change events -->
                  android:pathPrefix="/YourDataMapPathPrefix"/>
        </intent-filter>
</service>

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!