Android: How To Retrieve An Image From Res/drawable And Put It Into Webview.loadurl()
I already tried the following but without success. My project is using API level 4. from stackoverflow from android documentation Here is my code: webView.loadUrl('android.resource
Solution 1:
I believe you should have your drawables in assets/ folder, then refer to them through a URI in the form of file:///android_asset/drawable_name.png
, for example.
Solution 2:
In the end I have done the following:
I had an array of file name extensions of each of the image in resources. And then I could call the following method with the resource ID and it's file name extension.
protected String getResourceURL(int resourceId, String extension) {
String resName = getResources().getResourceName(resourceId);
int index = resName.indexOf("/");
resName = resName.substring(0, index);
index = resName.indexOf(":");
String resType = resName.substring(index + 1);
StringBuilder link = new StringBuilder(128);
link.append("file:///android_res/");
link.append(resType).append("/");
link.append(getResources().getResourceEntryName(resourceId));
link.append(".").append(extension);
return link.toString();
}
Solution 3:
You can get image path like this.
file:///android_res/drawable/YOUR_FILE_NAME
Pass this path to tag in html.It will work.
Solution 4:
I hope it is helpfull.. For getting image from res/drawable..
Resourcesres= getResources();
Drawabledrawable= res.getDrawable(R.drawable.myimage);
Post a Comment for "Android: How To Retrieve An Image From Res/drawable And Put It Into Webview.loadurl()"