I already tryed many ways to solve this, but nothing works.
making-wearablelistenerservice-ondatachanged-call-on-every-putdatamaprequest
wearablelistenerservices-ondatachanged-not-called-on-phone
AndroidManifest.xml
<service android:name="my.package.ListenerService"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="com.google.android.gms.wearable.DATA_CHANGED" />
<action android:name="com.google.android.gms.wearable.MESSAGE_RECEIVED" />
<data
android:host="*"
android:pathPrefix="/prefix"
android:scheme="wear" />
</intent-filter>
</service>
MainActivity
IntentFilter messageFilter = new IntentFilter(Intent.ACTION_SEND);
MobillsWearActivity.MessageReceiver messageReceiver = new MobillsWearActivity.MessageReceiver();
LocalBroadcastManager.getInstance(this).registerReceiver(messageReceiver, messageFilter);
Service
public class ListenerService extends WearableListenerService {
private final String TAG_WEAR = "[on-wear]";
@Override
public void onDataChanged(DataEventBuffer dataEvents) {
for (DataEvent event : dataEvents) {
// Check the data type
if (event.getType() == DataEvent.TYPE_CHANGED) {
DataMapItem dataItem = DataMapItem.fromDataItem (event.getDataItem());
String jsonString = dataItem.getDataMap().getString("listDespesas");
// Broadcast message to wearable activity for display
Intent messageIntent = new Intent();
messageIntent.setAction(Intent.ACTION_SEND);
messageIntent.putExtra("listDespesas", jsonString);
LocalBroadcastManager.getInstance(this).sendBroadcast(messageIntent);
Log.i(TAG_WEAR, "Recebido no wearable: "+jsonString);
}
}
}
@Override
public void onMessageReceived(MessageEvent messageEvent) {
Toast.makeText(this, "Received message", Toast.LENGTH_LONG).show();
}
}
The answer of Tom in this link works for me
There are two things you can check: