@Android display /res/viewable in WebView
This worked in android 2.2
<img src = "file:///android_res/drawable/q1.png" />
where q1.png is in the res/drawable-hdpi folder
Access a drawable resource as an image in a webview
(I assume you copied the code piece from your project.)
There is a typo:
String stringPath = "fie:///android_asset/chat_bubble.png";
should be
String stringPath = "file:///android_asset/chat_bubble.png";
And you didn't closed <img>
tag:
addOn = String.format("<img src=\"%s\" >", stringPath);
should be
addOn = String.format("<img src=\"%s\" />", stringPath);
Is it possible to use drawables (not images) in WebView?
You can insert Base64-encoded image data directly in the URL for the <IMG...> tag. The URL format is “data:mimetype;base64,data”. For example see here.
Load image from drawable folder to webview
this link : Android add image to webview from a drawable
You can only do such a thing if our image is inside your /assets folder. Also, you must load your html with a baseUrl that's inside your assets folder.
You can use WebView.loadUrl() or WebView.loadDataWithBaseURL():
webView.loadUrl("file:///android_asset/file.html");
or
webView.loadDataWithBaseURL("file:///android_asset/", "", "text/html", "utf-8", null);
(file.jpg should be inside your assets folder)
Too , see this link:
how to load a picture from my resource in webview?
Android: how to retrieve an image from res/drawable and put it into WebView.loadUrl()
Webview: Cannot display local image on phone but displays on emulator
Are you by any chance running the code on a phone with API Level < 8 (Android 2.1 and lower) and testing it on an emulator running a more recent version?
file:///android_res/...
only works for 2.2+.
Alternatively you can try putting the image in the assets folder and reference it by file:///android_asset/...
, which apparently is also supported on devices running older versions. Unfortunately you will lose the ability to automatically load up resources appropriate to the device's screen size and density.
Android add image to webview from a drawable
You can only do such a thing if our image is inside your /assets
folder. Also, you must load your html with a baseUrl that's inside your assets folder.
You can use WebView.loadUrl()
or WebView.loadDataWithBaseURL()
:
webView.loadUrl("file:///android_asset/file.html");
or
webView.loadDataWithBaseURL("file:///android_asset/", "<img src='file.jpg' />", "text/html", "utf-8", null);
(file.jpg should be inside your assets folder)
Using WebView Like this would work?
I am using drawables in src for tag in webview would this work?
Absolutely not. HTML expects URLs for images. Not to mention that you are specifying a widget ID, not a drawable resource.
sir that really helped but it is working correctly on emulator but not on the device .Do you know how to solve it?
Perhaps your device is older -- one answer on the question that Mr. Clayson linked to suggests that file:///android_res/
URLs only work on Android 2.2 and higher.
However, the android.resource
scheme has been around longer:
android.resource://[package]/[res type]/[res name]
e.g.:
android.resource://this.is.my.package/drawable/button
I have not tried this in WebView
, but it is worth a shot.
android webview marquee string can't replace some string with image
I think that your img src location is incorrect. Check out this question. I think the src should be 'file:///android_res/drawable/up.png'
.
Android 4.0 WebView.loadURL oddity
I updated last week from 2.3.4 to 4.0 on my HTC Sensation.
The two apps i wrote had a local HTML-Contact site.
On 2.3 it ran fine, now i get a "Webpage not available" site.
I found another post here on this site with the comment:
"Via some discussion with a Google engineer it seems that they've made the decision that the file:// scheme is insecure."
See here: Android 4.0.1 breaks WebView HTML 5 local storage?
Related Topics
Using Onclick Attribute in Layout Xml Causes a Nosuchmethodexception in Android Dialogs
How to Use Broadcast Receiver in Different Applications in Android
Why Is My Field 'Null' After Injection? How to Inject My Object
Firebase Messaging Nosuchmethoderror.Zzur Exception
Using the "Animated Circle" in an Imageview While Loading Stuff
What Are the Ipc Mechanisms Available in the Android Os
How to Run (Not Only Install) an Android Application Using .Apk File
Ndk - How to Use a Generated .So Library in Another Project
How to Retrieve More Than 1000 Rows from Parse.Com
How to Prevent Multiple Toast Overlaps
Can Not Set Debuggable Flag in Androidmanifest.Xml
Displaying Contact Number and Contact Name in a Custom List View
Android Spinner Error:Android.View.Windowmanager$Badtokenexception: Unable to Add Window
Could Not Launch Emulator in Android Studio
Live-Stream Video from One Android Phone to Another Over Wifi
Debugging with Android Studio Stuck at "Waiting for Debugger" Forever