Sudhu
Sudhu

Reputation: 170

React native -- call phone number with extension

I am trying to open phone number with extension. Linking works with just phone number

Tried with few options

Linking.openURL('tel:XXXXXXXXX,XXX');

Linking.openURL('tel:'+ encodeURIComponent('XXXXXXXXX,XXX'));

Dialer only dials primary number and doesnt include extension

I could write a native code and expose the method, but that would be my last option

Upvotes: 16

Views: 25019

Answers (2)

Code_Is_Law
Code_Is_Law

Reputation: 214

This is what i tried,

callNumber = (url) =>{
   Linking.canOpenURL(url).then(supported => {
   if (!supported) {
    console.log('Can\'t handle url: ' + url);
   } else {
    return Linking.openURL(url);
   }
 }).catch(err => console.error('An error occurred', err));
}

And the JSX,

<Text onPress={()=> this.callNumber(`tel:+91${user.number}`)}
       style = {[styles.value,{marginLeft : 5,textDecorationLine :'underline'}]}>{`+91 ${user.number}`}</Text>
</View>

Works fine for me. You may find more on linking here, https://facebook.github.io/react-native/docs/linking.html

Upvotes: 19

Mark
Mark

Reputation: 1099

I know it is late, but you can try this component: react-native-communications.

It works well both on iOS and Android.

You have to import it in the file you need:

import Communications from 'react-native-communications';

and then use it as you need:

<TouchableOpacity onPress={() => Communications.phonecall(phoneNumbers[0].number, true)}>

Upvotes: 25

Related Questions