RNFetchBlob.android.actionViewIntent is opening an empty view.
See original GitHub issueI’m using rn-fetch-blob 0.11.2 with react-native 0.61.3 to download files. While it works perfectly on iOS, I have an issue on android. It happens on android 10 (8 & 9 seem fine).
My code:
const DIRS = RNFetchBlob.fs.dirs
const FileManager = Platform.select({
ios: {
getDownloadPath: filename => DIRS.CacheDir + '/' + filename,
preview: path => RNFetchBlob.ios.openDocument(path)
},
android: {
getDownloadPath: filename => DIRS.DownloadDir + '/' + filename,
preview: RNFetchBlob.android.actionViewIntent
}
})
const path = FileManager.getDownloadPath(filename)
try {
const fetchConfig = {
fileCache: true,
path,
appendExt: filename.split('.').slice(-1)[0],
addAndroidDownloads: {
title: filename,
path,
notification: true,
mime: mimeType,
useDownloadManager: true,
mediaScannable: true
}
}
this.currentTask = RNFetchBlob.config(fetchConfig)
.fetch('GET', href, {
Authorization: config.credentials.header
})
.progress((received, total) => {
this.setState({ received, total })
})
const response = await this.currentTask
const downloadPath = response.path()
FileManager.preview(downloadPath, mimeType)
this.currentTask = null
} catch (error) {
this.currentTask = null
}
When I run this on android I’m getting this screen:
The file is correctly downloaded, the dl manager notification appears and if I tap the notification then the file is opened. But calling RNFetchBlob.android.actionViewIntent
right at the end of the download won’t open the file.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:4
- Comments:6
Top Results From Across the Web
RNFetchBlob.android.actionViewIntent does not working on ...
I fixed this issue by adding "queries" in AndroidManifest.xml <queries> <intent> <action android:name="android.intent.action.VIEW" /> <data ...
Read more >RNFetchBlob android, first view and then download the image ...
[Solved]-RNFetchBlob android, first view and then download the image-React Native. Search. score:1. android.actionViewIntent(PATH_OF_IMG, 'image/png').
Read more >react-native-blob-util - npm
A module provides upload, download, and files access API. Supports file stream read/write for process large files.. Latest version: 0.17.0, ...
Read more >types/rn-fetch-blob/index.d.ts - UNPKG
The CDN for @types/rn-fetch-blob. ... 123, readAsArrayBuffer(b: PolyfillBlob): void; ... For example, open Gallery app to view an image, or install APK.
Read more >react-native-file-writer - npm package - Snyk
How to show the written/exported file on file manager? RNFetchBlob.android.actionViewIntent(path, "application/json"); will show it to the user.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Was able to fix it by adding android:requestLegacyExternalStorage=“true” to my manifest file. Based on this https://medium.com/@sriramaripirala/android-10-open-failed-eacces-permission-denied-da8b630a89df
I also had this problem, you need to add request legacy for android 10, as stated by @gorbatenkov, but also request the READ_EXTERNAL_STORAGE and WRITE_EXTERNAL_STORAGE permissions (I believe only read is needed for opening a file with action view intent, if you don’t also need to download the file from a server before-hand). Requesting permissions is done via manifest for older android versions (before SDK version 23) as below:
For newer android versions, it must be explicitly done before using the action view intent (see https://reactnative.dev/docs/permissionsandroid) as below:
You should do both to support devices before and after SDK version 23.