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.
Modify src/MainActivity. java file to add WebView code. Run the application and choose a running android device and install the application on it and verify the results. Following is the content of the modified main activity file src/MainActivity.
Yes you can, you can use javascript to get webpage content. Then use the webview jsInterface to return the content to you java code.
2.1 To receive data from webview ,we can create an interface, which will enable webview to connect the native layer and pass data. From native layer, create a class and replicate the following. While configuring web view, we need to set JavaScript interface as above JSBridge class.
html file informs me that local storage is'nt supported by my browser (ie. the webview ). If you have any suggestion.. @Maetschl: if you want to change the code block from intentations to backticks, then at least remove the leading spaces.
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");
I also had to use loadDataWithBaseURL
instead of just plain loadData
to get the file:///android_res/drawable/page1.jpg
to work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With