React Native can't open any URL

2

help me please, tried many ways. Android error ==

E/ReactNativeJS( 4398): 'An error occurred', { [Error: Could not open URL 'https://www.facebook.com': No Activity found to handle Intent { act=android.intent.action.VIEW dat=https://www.facebook.com flg=0x10000000 }] framesToPop: 1, code: '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
asked on Stack Overflow Oct 7, 2016 by Alexander • edited Oct 7, 2016 by Thanh Pham

2 Answers

4

Sometimes this error appears if you provide an url without http:// or https://

answered on Stack Overflow Feb 22, 2019 by Thiago Brauer
1

You cannot assume you can open any URL, you must follow 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));
answered on Stack Overflow Oct 7, 2016 by rclai

User contributions licensed under CC BY-SA 3.0