Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 703
Sudhu Avatar asked Jun 28 '16 11:06

Sudhu


People also ask

How do I call a number in react-native?

To use call we have to install react-native-phone-call package. This command will copy all the dependencies into your node_module directory. –save is optional, it is just to update the react-native-phone-call dependency in your package. json file.

How do you input a phone number in react?

Explanation: In the above example first, we are importing the PhoneInput component and useState hook from react. Then we are using the useState hook to store the value of the phone number. After that, we are adding our phone input using the installed package.

How do you open call dialer in react-native?

import React from 'react'; import { View, Text, Linking, TouchableOpacity, Platform, StyleSheet, } from 'react-native'; const Home = () => { const openDialScreen = () => { let number = ''; if (Platform. OS === 'ios') { number = 'telprompt:${091123456789}'; } else { number = 'tel:${091123456789}'; } Linking.


2 Answers

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)}>
like image 102
Mark Avatar answered Oct 20 '22 23:10

Mark


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

like image 43
Code_Is_Law Avatar answered Oct 21 '22 00:10

Code_Is_Law