I have a pdf thats been downloaded and saved to the file system using FileSystem.writeAsStringAsync.
I would like to simply link to it and open it on the phone but have been unable to find a way to do so.
React Native’s Linking.openURL has not worked and Expo’s WebBrowser.openBrowserAsync crashes Expo entirely when I pass a file:// url to it.
Is there a solution to this? It seems to be a pretty simple use case. The use case for this is when the device has no internet so an online solution is not possible.
Failing this, is there a way to open or link to a pdf thats been bundled in the app?
The error I’m receiving when attempting to use openURL is
Could not open URL file:///data/user/0/host.expo.exponent/files/ExperienceData/%2540gooddog%252itransfuse/iTransfuseAppCache/BP/RC/rc.pdf: file:///data/user/0/host.expo.exponent/files/ExperienceData/%2540gooddog%252itransfuse/iTransfuseAppCache/BP/RC/rc.pdf exposed beyond app through Intent.getData()
The app is fairly complicated and would take some time to extricate into a simplified snack. I know this doesn’t help much with finding the issue, but perhaps you could give me some pointers based on the overall workflow of the app.
The app pretty much does the following.
The first time it is loaded, the app creates a number of folders and downloads a bunch of json files and pdfs into FileSystem.documentDirectory + 'iTransfuseAppCache/BP'. These files are then updated every day when the app is opened (assuming theres an internet connection), essentially caching them.
When a specific screen is opened, the app uses NetInfo.isConnected to check connection status and either collects data from the API if the device has internet, or collects it from the json files downloaded earlier.
On this page is a “View PDF” button. If the device has internet, when it is pressed, it loads the URL to a PDF (obtained from the API) into a WebView. If the devise does NOT have internet, it uses Linking.openURL to link to one the pdf that was downloaded. The URL for this cached file is something like file:///data/user/0/host.expo.exponent/files/ExperienceData/%2540gooddog%252itransfuse/iTransfuseAppCache/BP/RC/rc.pdf
Is this possible? Or are files downloaded to the FileSystem.documentDirectory folder completely inaccessible outside the app. If this is the case, is there a way to download these files to more accessible locations.