Could someone be kind enough to advise on the code needed in order to return the path to a file in Assets (all android versions, but will be targeting Android 11+)
I have seen getAssets() and getAssetsPath() in my research, but all examples are for android studio...
The File component, using the scope Asset and fullPath, doesn't work when compiled (A10 or A12)
Need something that works when the app is compiled
Works OK in companion. file:///storage/emulated/0/Android/data/edu.mit.appinventor.aicompanion3/files/assets/example.pdf
(I then strip off the file://)
But when compiled returns the path /android_asset/example.pdf
full path of file:///android_asset/example.pdf also fails to load the file
with Runtime Error open failed:ENOENT (no such file or directory)
My ViewPDF extension requires an absolute path to display a pdf. This works just fine for files in, for example, the ASD, but if i have files in the assets, I have to copy them over in order to display them. I would like to be able to provide a path to display directly from assets. (Image is using companion, but you should get the idea)
It might be better to internally use an InputStream to read the PDF rather than rely on a path in the file system. Assets are not stored in the file system in the traditional way--they're read from the AssetManager and come from inside of the APK file. Likewise, in some cases you might have a content:// URI which internally might map to a file on the file system but may not be accessible by your app unless you use the content URI. In both situations, Android provides an API to get an InputStream to read the content.
I guess it depends on what you're trying to do? Based on your blocks, it seems like you might be trying to render the PDF using a webviewer. In this case, I'd do something like:
Without knowing what the PDF API that you are using looks like, it is hard to guess. Hopefully, it would take an InputStream as an input in some form and would just read the contents from the stream.