Search code examples
androidreact-nativereact-native-fs

Open links inside pdf file on android is not working - react-native-pdf


Using react-native-pdf in my RN app. Property onPressLink - is not working on Android. On ios is all good.

Code snippet:

      <Pdf
        ref={(pdf) => {
          pdf = pdf;
        }}
        source={source}
        onLoadComplete={(numberOfPages, tableContent) => {
          setNumberOfPages(numberOfPages);
        }}
        onPageChanged={(page, numberOfPages) => {
          setCurrentPage(page);
        }}
        onPressLink={(uri) => {
          console.log("uri-", uri);

          openInBrowser(uri);
        }}
        style={styles.pdf}
      />

Also added to my AndroidManifest.xml:

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

react-native: 0.66.3

react-native-pdf: 6.6.0

Galaxy S20 - Android 11


Solution

  • Links in pdf should be set as hyperlinks - https://www.adobe.com/acrobat/resources/how-to-add-hyperlink-to-pdf.html

    ios recognize links which are just text just out of the box, that's why it works on ios devices.