react-native-pdf icon indicating copy to clipboard operation
react-native-pdf copied to clipboard

onPressLink doesn't work in android

Open baotoan1905 opened this issue 5 years ago • 9 comments

What react-native version are you using? 0.61.5 What react-native-pdf version are you using? 6.1.2 What platform does your issue occur on? (android/ios/both) Android - test in real device samsung note 8, android 9 Describe your issue as precisely as possible :

  1. Steps to reproduce the issue or to explain in which case you get the issue
    • Open PDF from remote url, press on some of urls inside pdf content, nothing happens, no log, no event trigger
  2. Interesting logs

Join a screenshot or video of the problem on the simulator or device?

Show us the code you are using?

renderPdf() {
    const { resource } = this.state;
    return (
      <Pdf
        source={{ uri: resource.src, cache: true }}
        onError={error => {
          console.log(error);
        }}
        style={styles.pdfContainer}
        onPressLink={handleOnPressUrl}
      />
    );
  }
async function handleOnPressUrl(url) {
  console.log('url', url);
  const supported = await Linking.canOpenURL(url);
  if (supported) {
    // Opening the link with some app, if the URL scheme is "http" the web link should be opened
    // by some browser in the mobile
    await Linking.openURL(url);
  } else {
    Alert.alert(`Don't know how to open this URL: ${url}`);
  }
}

baotoan1905 avatar Jun 03 '20 05:06 baotoan1905

Same error for me using react-native 0.63.3 and react-native-pdf 6.2.2

Links inside PDF don't trigger onPressLink event

Some help would be appreciated

therveux avatar Dec 14 '20 12:12 therveux

one year later... any update?

anatolyKhoronko avatar Dec 09 '21 14:12 anatolyKhoronko

it works for me having these setting on AndroudManfiest.xml

  <intent>
     <action android:name="android.intent.action.VIEW" />
     <data android:scheme="http"/>
  </intent>

  <intent>
      <action android:name="android.intent.action.VIEW" />
      <data android:mimeType="*/*" />
  </intent>
</queries>

samihabuawadSL avatar Jan 25 '23 11:01 samihabuawadSL

any update? it's still not working

  <queries>
    <intent>
      <action android:name="android.intent.action.VIEW" />
      <category android:name="android.intent.category.BROWSABLE" />
      <data android:scheme="http" />
    </intent>
    <intent>
      <action android:name="android.intent.action.VIEW" />
      <category android:name="android.intent.category.BROWSABLE" />
      <data android:scheme="https" />
    </intent>
    <intent>
      <action android:name="android.intent.action.VIEW" />
      <data android:mimeType="*/*" />
    </intent>
  </queries>

nikkizol avatar Mar 03 '23 13:03 nikkizol

@wonday

nikkizol avatar Mar 06 '23 12:03 nikkizol

@samihabuawadSL I added:

 <intent>
     <action android:name="android.intent.action.VIEW" />
     <data android:scheme="http"/>
  </intent>

  <intent>
      <action android:name="android.intent.action.VIEW" />
      <data android:mimeType="*/*" />
  </intent>
</queries>

but no luck... is there anything else should be done?

nikkizol avatar Mar 08 '23 11:03 nikkizol

all works, make sure links in pdf are set as hyperlinks - https://www.adobe.com/acrobat/resources/how-to-add-hyperlink-to-pdf.html

nikkizol avatar Mar 08 '23 14:03 nikkizol

@nikkizol Do we still need to add intent?

MuhammadRafeh avatar Dec 17 '23 10:12 MuhammadRafeh

Can anyone send his android manifest file?

MuhammadRafeh avatar Dec 17 '23 10:12 MuhammadRafeh