如何让WearOS Android App接收来自react-native app原生模块的消息?

问题描述 投票:0回答:1

我正在尝试使用 MessageClient Api https://developers.google.com/android/reference/com/google/android/gms/wearable/MessageClient 在 WearOS Android 应用程序和 React-native 应用程序之间发送消息使用本机模块(https://github.com/claired4l/react-native-wear-connectivity/tree/fix/message-client-send-message-interface)。

两个应用程序具有相同的应用程序 ID,并且设备已正确配对。

两个 Android 应用程序之间或两个反应本机应用程序之间的通信完美运行。然而,Android 和 React-Native 应用程序的混合设置面临着巨大的阻力。侦听器根本不会收到任何更新(使用实现 WearableListenerService 的后台服务没有更好的行为)。

sendMessage 和 onMessageReceived 背后的代码未知,我已经不知道如何完成这项工作了。有谁遇到过这个问题并解决了吗

android react-native google-play-services wear-os android-wear-data-api
1个回答
0
投票

默认情况下,react-native 在

android/app/debug.keystore
中提供了一个密钥库,该密钥库在应用程序 gradle 文件中设置以对调试 apk 进行签名。对于 Android 应用程序,没有预定义的密钥库,这导致 Android Studio 自动生成一个新签名,该签名与 React Native 应用程序使用的签名不同。

android {
    ...
    defaultConfig {
        ...
    }
    signingConfigs {
        debug {
            storeFile file('debug.keystore')
            storePassword 'android'
            keyAlias 'androiddebugkey'
            keyPassword 'android'
        }
    }
    buildTypes { 
        ... 
    }
}

当使用相同的密钥库和签名时,Android 应用程序和 React Native 应用程序就能够进行通信,而不会出现任何进一步的问题。

© www.soinside.com 2019 - 2024. All rights reserved.