React Native Send sms within the app

10,016

Solution 1

import { Linking,Platform  } from "react-native";

    const url = (Platform.OS === 'android')
    ? 'sms:919999999999?body=your message'
    : 'sms:919999999999'
    Linking.canOpenURL(url).then(supported => {
      if (!supported) {
        console.log('Unsupported url: ' + url)
      } else {
        return Linking.openURL(url)
      }
    }).catch(err => console.error('An error occurred', err))

Solution 2

After a lot of research and trials in the react app... I have found this library working fine and reached the goals to send a message without going into the default message environment.

var phoneNumbers = {
        "addressList": ["+911212121212", "+911212121212"]
      };
    var message = "This is automated test message"
    SmsAndroid.autoSend(
        phoneNumbers,
        message,
        (fail) => {
            console.log('Failed with this error: ' + fail);
        },
        (success) => {
            console.log('SMS sent successfully');
        },
    );

I hope it helps you. Do not forget to upvote

Share:
10,016
Imran Noor
Author by

Imran Noor

I am developing Apps on React Native and ReactJS.

Updated on June 04, 2022

Comments

  • Imran Noor
    Imran Noor almost 2 years

    I want to send sms to multiple numbers without opening to default messaging app. I try to use react-native-sms-x but its not maintained and my project just stuck at compiling. Also I used react-native-sms but it open default Messaging App filled with one user number and message body and had to click send button of it too.

    • Dylan
      Dylan about 4 years
      do you have a answer for this? I'm looking for the same function as well, thank you!
  • Imran Noor
    Imran Noor over 5 years
    I think it will open default sms app filled with given sms number and message.
  • Rushabh Gedam
    Rushabh Gedam almost 4 years
    This is the best library I've ever worked, just to ask your experience is it helped to you ?