Loading an Android Resource into a WebView

android, android-webview

Solution

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");

Problem

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 `WebView` like so: ``` webView.loadUrl("file:///android_asset/page1.jpg"); ``` 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 `res/drawable` 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 `"file:///res/drawable/pagetitle.jpg"` with no success. Thanks for the help. Update: I found that `"file:///android_res/drawable/page1.jpg"` was the path that I was looking for.

Original source