13

Description

Cannot open phone call with Linking.openURL('tel:+123456789')

Environment

Environment: OS: macOS High Sierra 10.13.4 Node: 8.5.0 Yarn: Not Found npm: 5.8.0 Watchman: Not Found Xcode: Xcode 9.3 Build version 9E145 Android Studio: 2.3 AI-162.4069837

Packages: (wanted => installed) react: 16.3.1 => 16.3.1 react-native: https://github.com/expo/react-native/archive/sdk-27.0.0.tar.gz => 0.55.2 expo: 27.0.1,

Steps to Reproduce

import ...
export default class App extends React.Component {

_pressCall=()=>{
    const url='tel:+123456789'
    Linking.openURL(url)
}

render() {
    return (
        <View style={styles.container}>
            <Button title='call' onPress={this._pressCall}/>
        </View>
    );
}
}

https://snack.expo.io/@kikoololmdrxdd/test-linking-phone-call

Expected Behavior

open phone call

Actual Behavior

[Android]Error message
attempt to invoke virtual method 'boolean java.lang.string.endsWith(java.
lang.String)' on a null object reference
Riki Chou
  • 509
  • 1
  • 3
  • 13

4 Answers4

24

I found a solution: you need to convert 'tel:' to 'tel://'

Riki Chou
  • 509
  • 1
  • 3
  • 13
  • ` if (/tel\:/.test(navState.url)) { Linking.openURL(`tel://${navState.url.split('tel:').pop()}`) this._webViewRef.stopLoading() }` I am using this code but still, my app is crashing. – sidverma Mar 03 '21 at 16:28
  • 1
    Thanks for the solution! Do you maybe know why you need the prompt to be with `//` now? On iOS it works fine without them, just not on Android. The official RN docs also show the `tel:` one so it's strange. – Arnas Savickas Jan 11 '22 at 13:18
  • iOS seems to need the // now on RN 0.71.8 – Aureo Beck May 25 '23 at 12:09
9

tel: worked on Android

tel:// worked on Iphone

ggDeGreat
  • 1,098
  • 1
  • 17
  • 33
2

tel:// works for iPhone and Android. RN 0.61

Priyank_Vadi
  • 1,028
  • 10
  • 27
0

This Worked for me I found a solution: you need to convert 'tel:' to 'tel://'

Linking.openURL(tel://${phone})