0

I am using a WearableListenerService on the handheld to retrieve data for the wearable. I recently updated my code, and switched from sending a large set of DataMap objects to a single DataMap holding a byte array.

The code was working, but as I continued testing, I started getting an empty byte array on the wearable. This is a case that I allowed, but I checked the DataMap on the handheld and it is sending data.

So I switched the code on the handheld and wearable back to the old implementation of a set of DataMap objects. The device is sending the correct data, but the wearable throws a java.lang.ClassCastException, stating a byte[] cannot be cast to java.lang.String. So the wearable is still getting the empty byte array that I had been getting previously.

I am testing on the wearable emulator, and I do not have a physical device to test on. Am I doing something wrong? Is there any way to make sure the Data Layer has updated data?

Bryan
  • 14,756
  • 10
  • 70
  • 125

2 Answers2

1

I faced this problem before and i solved it by replacing DataMap with MessageApi, and i used Gson library https://github.com/google/gson (that can be used to convert Java Objects into their JSON representation) to send java objects and custom objects between mobile and wear. i hope this help you

mahmoud moustafa
  • 223
  • 3
  • 11
1

This is a longstanding issue with the Data API, and while it's better than it used to be, it still does happen. The only resolution I know of is to clear the data layer completely and start over, following the instructions at http://www.tinmith.net/wayne/blog/2014/08/android-wear-total-reset.htm

Sterling
  • 6,365
  • 2
  • 32
  • 40
  • 1
    Wayne Piekarski (the Google dev advocate who wrote the blog post I linked to) has stated that his "total reset" procedure should no longer be necessary. If you're still having this problem with current versions of the API and OS, I suggest you post details on the Wear developer G+ community, where he's likely to see it (and be able to follow up with you). https://plus.google.com/u/0/communities/113381227473021565406 – Sterling Aug 06 '16 at 20:15