Loading .js and .html files from /data/data/xyz or sdcard on android

Sorry if this question has been asked before, but I’m wanting to load files within the Webview that will be saved either in my apps /data dir (such as /data/data/com.myapp/somefile.js) or sdcard (/sdcard/myapp/somefile.js)

I’m not trying to load the files using a file API within javascript, but within HTML, such as

<img src="file:///data/data/com.myapp/somefile.jpg" />

or

<script src="file:///sdcard/myapp/somefile.js"></script>

Thanks

I would be surprised and quite dismayed if this was possible.

Understandably loading from sdcard could come with significant risk when loading .js file (as with any other app type that utilizes sdcard for nontrivial data) but the /data dir is readable/writable only to the app that owns it. I would hate to use this approach (if available) if a risk exists that I don’t fully understand, so your input is very welcome.

Let’s stick with images, because I like all executable code in an app to be included inside the app bundle for security assurance reasons.

If the goal is to display an image within the app that is initially stored somewhere accessible to the app (different platforms have different restrictions on what this means), such as a personal avatar, I think your best bet would be as follows:

1 Like

I haven’t yet published an app yet so please forgive my ignorance if incorrect, but I’m of the understanding that an apps /data dir (/data/data/<package_name>) is strictly only accessible to the app that owns it unless a different app has root privileges. Is this incorrect? Correct but poor practice? I greatly value your help in this matter, thanks

I don’t think this matters to the people writing browsers. Can we talk about what you really are trying to achieve and how we can best do that?