Reputation: 2660
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.
Upvotes: 48
Views: 47046
Reputation: 181
I also had to use loadDataWithBaseURL
instead of just plain loadData
to get the file:///android_res/drawable/page1.jpg
to work.
Upvotes: 6
Reputation: 3890
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");
Upvotes: 22