briankabiro/react-native-get-sms-android

send msg to multiple numbers

areebvohra opened this issue ยท 7 comments

i want to send msg to multiple numbers at once
this is what i'm doing, but getting error "com.facebook.bridge.ReadableNativeArray cannot be cast to java.lang.String"

someFunction = () => {
    SmsAndroid.autoSend(
      ['03422114890', '03422114999'],
      'hello',
      (fail) => {
        alert(fail);
      },
      (success) => {
        alert(success);
      },
    );
  }

i also tried this

someFunction = async () => {
    var phoneNumber = {
      "addressList": ["123", "456"]
    }

    SmsAndroid.send(
      phoneNumber,
      'hello world',
      (fail) => {
        alert(fail);
      },
      (success) => {
        alert(success);
      },
    );
  }

i'll be damned, it was so simple
why hasn't this been mentioned in the docs please add this to the README ๐Ÿ™

someFunction = async () => {
    var phoneNumber = {
      "addressList": ["123", "456"]
    }

    SmsAndroid.send(
      JSON.stringify(phoneNumber),
      'hello world',
      (fail) => {
        alert(fail);
      },
      (success) => {
        alert(success);
      },
    );
  }

Sorry about that, @AreebVohra. Glad to see that you found a solution.

Let me open up a PR to update the README with the information. ๐Ÿƒ ๐Ÿƒ

Done and merged.

Thanks again for including the code!

Done and merged.

Thanks again for including the code!

hello @briankabiro i tried your code that you added in the README it will not work because if you look in the android native code it requires a json object with key "addressList"
i recommend you try running the code and see the outcome

let phoneNumber = {
      "addressList": ["123", "456"]
    }

like this

You are right, Areeb.

It does expect the addressList key. I'll make sure that I test it out

@AreebVohra I keep getting Failed with this error: Generic failure using your example

    let numbers = {
      "addressList": ["+2349****", "+2348****"]
    };
const message = "Hey this is automated"

    SmsAndroid.autoSend(
      JSON.stringify(numbers),
      message,
      (fail) => {
        console.log('Failed with this error: ' + fail);
      },
      (success) => {
        alert(JSON.stringify('SMS sent successfully'))
        console.log('SMS sent successfully' + success);
      }
    )

@adefemi171 i have not used this package in a while