Home > Net >  Is it possible open mail or phone call with Linking.openURL in react native?
Is it possible open mail or phone call with Linking.openURL in react native?

Time:11-23

I need to make a call when I click on the button, or open mail in order to send a message, we usually use the a tag with the necessary mail: or tel: attributes for these purposes, but is it possible to do this using Linking.openURL like this?

onPress={() => Linking.openURL(' 380775454545455')

If it possible, what should we add in order to do it?

CodePudding user response:

Mail:

const subject = "Mail Subject";
const message = "Message Body";
Linking.openURL(`mailto:[email protected]?subject=${subject}&body=${message}`)

Phone call:

const phone = " 380775454545455";
Linking.openURL(`tel:${phone}`)

CodePudding user response:

As referred to in the react-native's documentation you can open your mail or make a phone call using the Linking component.

Phone call:

const phoneNumber = " 123456789";
Linking.openURL(`tel:${phoneNumber}`);

Email:

const email = "[email protected]";

// if you want to just open the mail app
Linking.openURL(`mailto:${email}`);

// if you want to open the mail app with subject and body
const subject = "Subject";
const body = "Body";

Linking.openURL(`mailto:${email}?subject=${subject}&body=${body}`);

You can also use the component to open a website, send an SMS, or even open other apps through Deep Linking. For further explanation please see the documentation

  • Related