Amplify91 Amplify91 - 1 year ago 94
Android Question

Loading an Android Resource into a WebView

I have an Android app that displays a comic book. To make use of the built-in zoom controls, I am loading the pictures in a

like so:


This is working just fine, however, since the images are in the assets folder, they are not being compressed which makes my .apk enormous. I was wondering how to reference resource files (from the
folder) with a file path like I did above with the assets. Does anyone know what that path would look like? I've tried things like
with no success. Thanks for the help.


I found that
was the path that I was looking for.

Answer Source

from this site

Using the resource id, the format is:

"android.resource://[package]/[res id]"

Uri path = Uri.parse("android.resource://com.androidbook.samplevideo/" + R.raw.myvideo);

or, using the resource subdirectory (type) and resource name (filename without extension), the format is:

"android.resource://[package]/[res type]/[res name]"

Uri path = Uri.parse("android.resource://com.androidbook.samplevideo/raw/myvideo");