Open ciriousjoker opened 1 year ago
Apparently you can write something like this to convert it:
/**
* Interprets the byteArray as a Map<String, Any>.
* If that's not possible, returns null.
*/
fun ByteArray.asMap(): Map<String, Any>? {
val byteArrayInputStream = ByteArrayInputStream(this)
val objectInputStream = ObjectInputStream(byteArrayInputStream)
return try {
val obj = objectInputStream.readObject()
if(obj !is Map<*, *>) throw Exception()
@Suppress("UNCHECKED_CAST")
obj as Map<String, Any>;
} catch (e: Exception) {
e.printStackTrace()
null
} finally {
objectInputStream.close()
}
}
...
val data = messageEvent.data.asMap()
The idea is you use flutter on both sides, but I should probably expose those conversion methods so people doing native android can use them without copy/paste
Actually nevermind you wouldn't have access to the flutter plugin on the native android side 🙃. Maybe I should make a native android wrapper, but that's a task for another day.
Yeah, I found the conversion methods and after copypasting them the serialization and deserialization works.
Using flutter for the wear os app isn't really an option. Battery life is extremely limited and we want to use the native widgets due to their looks and performance.
It would be nice to have a section in the readme about how to send and receive data in a native wearOS app.
I'm sending data like this:
I'm trying to receive it like this:
The result is something like this (from logcat):