Skip to content

Add information to readme for sending/receiving data in native android app #7

Description

@ciriousjoker

I'm sending data like this:

await watch.sendMessage({
  "type": "test",
  "data": "Hello from Flutter",
});

I'm trying to receive it like this:

class CommunicationService : WearableListenerService() {
    override fun onMessageReceived(messageEvent: MessageEvent) {
        super.onMessageReceived(messageEvent)
        Log.d(TAG, "onMessageReceived: ${messageEvent.path}")

        // Process the received message
        handleMessage(messageEvent.path, messageEvent.data)
    }

    private fun handleMessage(path: String, dataBytes: ByteArray) {
        val data = String(dataBytes, Charsets.UTF_8)
        val data2 = dataBytes.toString()
        Log.d(TAG, "data: $data")
        // Handle the message based on the path and data
    }

    companion object {
        private const val TAG = "CommunicationService"
    }
}

The result is something like this (from logcat):

data: ��??�sr??�java.util.HashMap������`��??�F??
loadFactorI?? thresholdxp?@?????????? w�??????�??????�t??�datat??�Hello from Fluttert??�typet??�testx

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions