Expo 31: Android SMS Error Executing exported method sendSMSAsync on module ExpoSMS

#1

Hi guys,
Super excited to use the newest SDK (31) to implement sending SMS from the app. On iPhone I was able to implement it very quickly, and the docs were a big help.

However, I’m testing on an actual Android device and am getting an error whenever I go to execute the sendSMSAsync method. The error is as follows:

Encountered an exception while calling native method: Exception occurred while executing exported method sendSMSAsync on module ExpoSMS: null
- node_modules/react-native/Libraries/BatchedBridge/NativeModules.js:95:55 in <unknown>
- node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:397:4 in __invokeCallback
- ... 4 more stack frames from framework internals

The device has granted permisson to use the SMS module, but it seems that there is something else blocking the execution. I’d expect the phone’s native SMS app to open up with my prepopulated message body, just like it does for iOS.

Here’s the involved code, which again executes perfectly on iOS:

  componentDidMount = async () => {
    const isAvailable = await SMS.isAvailableAsync();
    if (isAvailable) {
      this.setState({isAvailable: true})

      const { status } = await Permissions.askAsync(Permissions.SMS)
      if (status !== 'granted') {
        Alert.alert(`Hey! If you give us permission to send text messages, you can send these tee time details to your playing partners! Go to your phone's settings to enable!`);
        return
      }
      Alert.alert("permission status: ", status);
      this.setState({isGranted: true})
    }
  }

  _sendSMS = async () => {
    await SMS.sendSMSAsync([], this.props.message).then((result) => {
      console.log(result["result"])
      this.props.handleResult(result["result"]);
    }).catch(err => {
      console.log(err)
    })
  }

The error I reported above is in the terminal, while executing expo start. It just shows up in the logs.

Any idea what can be going on?

Yes, the Expo app on the android device is the latest, and the CLI is updated as well.

#2

Hey @trev91,

Very happy to hear your excitement surrounding upgrading to our newest SDK! However, definitely sad to hear that you’ve run into this issue with the SMS API. After running a quick test on Snack, it appears that iOS is able to elegantly handle an empty array passed into the addresses argument while on Android it throws the aforementioned error. You’ll find if you pass a single phone number as a string or an array of strings, it will work properly on Android.

Is your intended use to just have a pre-populated message and then allow the user to manually enter their intended recipient(s) phone number(s)?

Cheers,

Adam

#3

Thank you for getting back to me. I appreciate your time!

My intended use is to only have a pre-populated message and then allow the user to manually enter their intended recipients. Is the workaround potentially sending in a single character string for the addresses argument then for Android? That doesn’t seem professional, so if you have another idea on this, I’m all ears!

#4

We’re here to help! I created an issue on our github repo: https://github.com/expo/expo/issues/2673 You can keep track of the issue there. Hopefully we can get it fixed soon. I just tried passing a single empty string SMS.sendSMSAsync("", "Android SMS test") and it seems to work as you would want. Like you said, not ideal but it seems to be a serviceable workaround in the interim.

1 Like
#5

Awesome! I will follow the issue there.

Thanks for the temporary workaround solution. Looking forward to a fix!

1 Like
closed #6

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.