android WebView cannot show the image in release mode - android

WebView wv = new WebView(this.context);
wv.loadDataWithBaseURL("file:///android_res/drawable/", "...<img src="my_pic.png ..."", "text/html", "UTF-8", null);
the html is actually in string, i just made it easy to read.
I used above code to populate some html to a WebView to display an image in drawable,
it is fine in debug mode, but a broken image icon results if I install a apk directly.
i am suspecting proguard, but seems doesn't make sense.
anyone experienced please help me ...
thank you

Related

Webview doesn't display text with color

In my app I display some Html content in webview:
String webViewConent = 'this is some <span style="color:#2ecc71">sample</span> string'
webView.loadData(omowienie, "text/html; charset=utf-8", "UTF-8");
However after last app update, which was related with some other thing, for some users webview doesn't work correctly. They see only string which is before span tag. The problem is not related to any specific android version.
Same problem here, I found base64 encoding as a quick fix:
String base64 = android.util.Base64.encodeToString(html.getBytes("UTF-8"), android.util.Base64.DEFAULT);
mWebView.loadData(base64, "text/html; charset=utf-8", "base64");
I had the same issue today. As a simple workaround I replaced hex colors in CSS by RGB equivalents.
Before
<span style="color: #3050c0">Some text</span>
After
<span style="color: rgb(48, 80, 192)">Some text</span>
I found the approach in this answer on WebView encoding seems to fix this issue. Instead of using loadData, try loadDataWithBaseURL:
webview.loadDataWithBaseURL(null, html, "text/html; charset=utf-8", "utf8", null)
I have same problem. My app does not display text after span tag. Some devices works fine but some devices does not work. Upvoted!
<p><span style="color:#0000CD"><strong>Materials:</strong></span></p>
As a result of my research and experimentation, I have disabled the Android System Webview application on my device. As a result of this process, my application worked correctly. However, to me, this cannot be a solution. What are your ideas?
I think the problem is the new update in Android Webview System. The old version works for me.
My alternative solution here is to uninstall Android Webview System in your phone so that you can have the default version(this solution is not ideal if your app is uploaded in Google Playstore and have a lot of users)
The second option is you can delete your color and background color codes in html for the meantime and it will work(I think it is Android Webview System's bug and we just need to wait until they fix their issues)
I have same problem. It may be the Android WebView System's bug but the solution is using font tag to color the texts.
String webViewConent = "this is some <font style="color:green">sample</font> string";
Note : This code is not working for Hex format colors
I din't find a fix but I was able to do a work around changing the string with the original HTML. This might help someone else, AS LONG AS YOU ALREADY KNOW THE COLOURS YOUR ARE GOING TO DISPLAY:
String newString = originalString.replaceAll("color:#888888", "color:gray");

How can I embed the new GIFV format on my android app?

I would like to know if one of your could embed GIFV format into your app. I am trying to embed it using a webview but without success.
Actually GIFV format is closer to a video format than a gif.
Whatever suggestion would be nice. Thanks in advance.
After work around of this issue, I couldn't find a solution which could display GIFV format like a video.
But, my solution to this issue has been to use a webview using the same way that i was using to make able to load "gif" files and if you remove directly the "v" from the name of the file, you can show it as a .gif file.
Resuming, remove the "v" from the .gifv file name and display it as a .gif.
The way that i am injecting code to make able to display gifs into the webview is:
public void getContentWebView(String url, WebView webView)
{
String html = "<!DOCTYPE html><html><body><img src=\""+ url +"\" width=\"100%\" height=\"100%\"></body></html>";
webView.loadData(html, "text/html", "utf-8");
}

How do I get my android webview make a load locally

I have a doubt. What happens is the following:
I exported my game by using cocoonjs contruct 2, but I want to run it on my android webview by, because I want to implement starApp, and cocoonjs not support this.
So, using my code below, I get only a blank screen.
But in my launcher cocoonjs, this same project works normally, just that I select Canvas + can anyone help me?
web = (WebView) findViewById(R.id.webInicial);
web.setWebChromeClient(new WebChromeClient());
web.getSettings().setJavaScriptEnabled(true);
web.loadUrl("file:///android_asset/www/index.html");
webView.loadData(yourData, "text/html", "UTF-8");
Where youData is the actual HTML data.
Have you tried getApplicationContext().getAssets().open("www/index.html");?
If that doesn't work, I'd say try the solutions in this post and let us know if it worked for you.

Frameset not working in android 4.0 webview

I want to use two html in a single webpage so i choose to implement frameset in html. it works fine in all android version except android4.0. If i html file in default browser its working fine but in webview only one frame is loaded not the other ie first frame is override by second frame so it looks only second frame is loading.
here is my code for loading html in webview..
WebView web=new WebView(this);
String url="<html><frameset cols=\"25%,25%\" FRAMEBORDER=NO FRAMESPACING=0 BORDER=0><frame src=\"file:///android_asset/preview.html"
+"\" /><frame src=\"file:///android_asset/preview.html\" /> </frameset></html>";
web.loadDataWithBaseURL("file:/"+baseurl+"/",url, "text/html", "utf-8","");
i dont know why its not supporting in android4.0 whether android webview is not accepting frame in 4.0 or not? If anyone knows please help me..

Android +1 button in WebView

I've tried putting Google's +1 button in WebView using the methods they describe. I've initialized the WebView as follows:
final WebView web = (WebView)findViewById(R.id.webView);
web.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
web.getSettings().setJavaScriptEnabled(true);
web.getSettings().setSavePassword(false);
web.getSettings().setBuiltInZoomControls(false);
web.getSettings().setUseWideViewPort(true);
web.getSettings().setLoadWithOverviewMode(true);
web.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
web.setHorizontalScrollBarEnabled(false);
web.setBackgroundColor(0xff2e2e2e);
web.loadDataWithBaseURL(null, htmlCodeGoesHere, "text/html", "utf-8", null);
And the html code:
<script type="text/javascript" src="https://apis.google.com/js/plusone.js"></script>
<g:plusone href="http://stackoverflow.com"></g:plusone>
The problem is... the button doesn't display at all.
How do I fix it? By the way - I also want the button to launch a new window instead using the WebView. Is there a simple solution?
Thanks
The problem lies in permissions system in WebView. Scripts in local files have problems accessing external resources. The solution is to make WebView think local code was loaded from external website.
web.loadDataWithBaseURL("http://fake.com", htmlCodeGoesHere, "text/html", "utf-8", null);
The button will appear, but unfortunetely it doesn't work well in WebView.
I am not too experienced with WebView, but the fact the the button doesn't show up at all, sounds like it could be an issue in your layout/main.xml file. Have you taken a look at this yet?
Also, for the button to launch a new window, I think it is possible to attach an setOnClickListener, once that is done just treat it as a button, and open a new window. I hope that is possible.

Categories

Resources