Nad*_*bit 6 android react-native
我正在尝试使用React Native打开.pdf,.docx,.xlsx和其他类似文件。
我目前正在将文件从amazon s3存储桶下载到设备,然后尝试使用react-native-fetch-blob 在设备上打开它们android.actionViewIntent(res.path(), mimeType)。
这适用于图像,但是与其他任何东西一样,我得到以下错误:
Error: No Activity found to handle Intent { act=android.intent.action.VIEW dat=file:///storage/emulated/0/Android/data/myappname/files/1475.pdf typ=application/pdf flg=0x10000000 }
编辑:对于任何想看到最终实现的实现的人(使用react-native-file-system和react-native-fetch-blob):
const fileType = fileDownloadPath.split('.').pop();
const SavePath = Platform.OS === 'ios' ? RNFS.DocumentDirectoryPath : RNFS.ExternalDirectoryPath;
const mimeType = getMimeType(fileType); // getMimeType is a method (switch statement) that returns the correct mimetype
const path = `${SavePath}/${filename}.${fileType}`;
const android = RNFetchBlob.android;
RNFS.downloadFile({
fromUrl: url,
toFile: path,
}).promise.then(() => {
android.actionViewIntent(path, mimeType)
.then((success) => {
console.log('success: ', success)
})
.catch((err) => {
console.log('err:', err)
})
});
Run Code Online (Sandbox Code Playgroud)
显然,您的设备没有安装其他文件查看器应用程序,例如 Polaris Office 或 Office 套件或任何其他此类文件查看器。
通常,这是此类问题的例外情况。您可以显示警告/吐司或显示一些链接以从 Play 商店下载这些应用程序。
| 归档时间: |
|
| 查看次数: |
4160 次 |
| 最近记录: |