使用 react-native 和 expo 使用外部 pdf 查看器启动本地 pdf 文件

Launch local pdf file with external pdf viewer using react-native and expo

我是 react-native 的新手。我的移动存储上有一个示例 pdf 文件,并尝试使用 IntentLauncher.startActivityAsync 在外部 pdf 查看器中启动。它启动外部应用程序但不打开文件。这是我的代码,

      IntentLauncher.startActivityAsync("android.intent.action.VIEW", {
        data: FileUri, 
        flags: 1,
        type: "application/pdf",
      });

这是我的文件-url:'/storage/emulated/0/MyFolder/sample-file.pdf'.

我认为数据(密钥)可能有误。我该如何解决?

没有别的办法,现在我正在使用 React Native CLI 来解决这个问题。

react-native-file-viewer 满足了我的需求。这是我的代码,

  const granted = await PermissionsAndroid.request(
    PermissionsAndroid.PERMISSIONS.READ_EXTERNAL_STORAGE,
  );
  if (granted === PermissionsAndroid.RESULTS.GRANTED) {
    FileViewer.open(path, {showOpenWithDialog: true})
      .then(() => {
        // something useful here
      })
      .catch((err) => {
        console.log('err: ', err);
      });
  } else {
    console.log('Permission denied');
  }

这是我的路径:'file:///storage/emulated/0/Download/test.pdf'