【问题标题】:React Native can't open any URLReact Native 无法打开任何 URL
【发布时间】:2025-12-19 16:15:12
【问题描述】:

请帮助我,尝试了很多方法。安卓 错误 ==

E/ReactNativeJS(4398): '发生错误', { [错误: 无法打开 URL 'https://www.facebook.com': 找不到要处理的活动 意图 { act=android.intent.action.VIEW dat=https://www.facebook.com flg=0x10000000 }] framesToPop: 1, 代码: 'EUNSPECIFIED' }

_onPressButton() {
    Linking.openURL('https://www.facebook.com').catch(err => console.error('An error occurred', err));

  }
  render() {
    return (
      <View style={{paddingTop: 22}}>
        <ListView
          dataSource={this.state.dataSource}
          renderRow={(rowData) =>  
            <TouchableHighlight  onPress={this._onPressButton} > 
              <View style={{marginBottom:10, marginLeft:5, flex: 1, flexDirection: 'row',justifyContent: 'flex-start'}}>

              <View style={{width:30}}><Image source={{ uri: rowData.img }} style={{width:25, height:25, marginTop: 5}} /></View>
              <View style={{alignSelf: 'stretch'}}>
              <Text>{rowData.title}</Text>
              <Text style={{fontSize:10}}>{rowData.author}, {rowData.company}, {rowData.time}</Text>
              </View>
            </View>
            </TouchableHighlight>


          }
        />
      </View>
    );
  }

【问题讨论】:

    标签: android react-native


    【解决方案1】:

    如果您提供的网址不带 http:// 或 https://,有时会出现此错误

    【讨论】:

      【解决方案2】:

      你不能假设你可以打开任何网址,你必须关注this procedure

      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));
      

      【讨论】:

      • 谢谢!但是当我这样做时,我会显示此日志信息:“无法处理 url:facebook.com