无法使用Linking.openURL打开电话

Rik*_*hou 5 android react-native expo react-native-linking

描述

无法使用Linking.openURL('tel:+123456789')打开电话

环境

环境:操作系统:macOS High Sierra 10.13.4节点:8.5.0纱线:找不到npm:5.8.0值班员:找不到Xcode:Xcode 9.3 Build版本9E145 Android Studio:2.3 AI-162.4069837

软件包:(需要=>已安装)反应:16.3.1 => 16.3.1 react-native:https : //github.com/expo/react-native/archive/sdk-27.0.0.tar.gz => 0.55 .2世博会:27.0.1,

重现步骤

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>
    );
}
}
Run Code Online (Sandbox Code Playgroud)

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

预期行为

拨打电话

实际行为

[Android]Error message
attempt to invoke virtual method 'boolean java.lang.string.endsWith(java.
lang.String)' on a null object reference
Run Code Online (Sandbox Code Playgroud)

Rik*_*hou 11

我找到了解决方案:您需要将'tel:'转换为'tel://'

  • 感谢您的解决方案!您可能知道为什么现在需要带有“//”的提示吗?在 iOS 上,没有它们也能正常工作,但在 Android 上却不行。RN 官方文档还显示了“tel:”,所以这很奇怪。 (2认同)

ggD*_*eat 5

tel: 在 Android 上工作

tel:// 在 iPhone 上工作