ssttonn / flutter_wear_os_connectivity

A plugin that provides a wrapper that enables Flutter apps to communicate with apps running on WearOS.
BSD 3-Clause "New" or "Revised" License
11 stars 18 forks source link

Flutter Wear OS app with Flutter android app #4

Open ConnorDykes opened 8 months ago

ConnorDykes commented 8 months ago

I created a flutter app for wear os and a flutter app for android. I am trying to use the package on the watch app to send a message to the phone app. it appears to be sending but I cannot listen to the messages on the phone. The watch is paired with the phone. Both the phone and the watch can see the id of each other and they both appear to be sending a message. I initiate a listener but I never get any messages.
here is the code for my listener on the phone side

 _flutterWearOsConnectivity
          .messageReceived()
          .listen((WearOSMessage message) async {
        print(message);
        if (message.path == '/six') {
          print('got message for path);
        }
      });

here is the code I am using to send the message from the watch to the phone app :

Future<void> sendDataToPhone(double hr) async {
    DateTime currentTime = DateTime.now();

    int timestamp = currentTime.millisecondsSinceEpoch;

    try {

      final connectedNodes =
          await _flutterWearOsConnectivity.getConnectedDevices();

      final data = convertToUint8List({'hr': hr, 'ts': timestamp});

      await _flutterWearOsConnectivity
          .sendMessage(data,
              deviceId: connectedNodes.first.id,
              path: '/six',
              priority: MessagePriority.high)
          .then((value) => setState(() {
                print("message Sent"); 
                time = DateTime.now().second.toString();
              }));
    } catch (e) {
      print(e.toString());
      setState(() {
        time = e.toString();
      });
      print('Failed to send data to phone: $e');
    }
  }

Both the apps have the same applicationId in the build.gradle. I would appreciate some guidance if you have it.

ConnorDykes commented 8 months ago

Please Help

trabulium commented 6 months ago

I'm getting the exact same experience here. Everything seems to send Ok from either device but nothing is ever received. If I send from the watch to its own deviceID, the message is received fine and if I send from the phone to its own deviceID, the message is received also but if I send to each other, nothing is received. Did you manage to get anywhere with this?

deveshm commented 4 months ago

Facing the same issue here, using Flutter for Android App and Kotlin for WearOS app (both have the same application ID)

deveshm commented 4 months ago

After some debugging I figured out my issue. Here are some steps you can take to validate that the apps can talk to each other:

  1. Make sure the application ID and signing config is the same for both applications 1.1. You can use a flutter package like package_info_plus or the underlying kotlin/java code behind it to validate your application ID and signatures match for both applications.
  2. Make sure you call the same underlying communication method to send the message as this package uses to receive it i.e. use messageclient.sendMessage. OP is already doing this by using the package's sendMessage function, but I'm mentioning this as this was the mistake I made.