I has a app that loads a url on a WebView.
web = (WebView) findViewById(R.id.webview);
WebSettings settings = web.getSettings();
settings.setJavaScriptEnabled(true);
settings.setJavaScriptCanOpenWindowsAutomatically(false);
settings.setSupportMultipleWindows(false);
settings.setSupportZoom(false);
settings.setPluginsEnabled(true);
web.setVerticalScrollBarEnabled(false);
web.setHorizontalScrollBarEnabled(false);
web.loadUrl(lastUrl);
But a spot that should has Video first shows a "loading" view than disappears, if a tap on it occurs, the sound of the video starts playing but not show.
PS: I came across answers that told to add the hardwareAccelerated flag on Manifest, but this solutions simply does not work here.
I used settings.setDomStorageEnabled(true) as well with hardwareAccelerated="true" and it's working.
Did you see this question and the comment from slytron?
By the way setPluginsEnabled is deprecated in favor of setPluginState as of API level 8.
Related
In writing cross platform software, I made the design decision to write the the views once in HTML so they would be the same on the website, iOS and andorid apps. I'm trying to display them on Android with a WebView.
The views are animated, and so I generate new HTML at least 10 times a second and update them with:
webView.LoadData(htmlString, "text/html", "UTF-8");
webView.PostInvaldiate();
However, the Web View only seems to update once every 2 seconds, at its quickest.
Am I completely overloading the UI Thread? I'm assuming WebViews were never designed for this.
Is it possible to display an animated view like this (using HTML) in Android, or do I need to cut my losses and go back and rewrite the whole thing using an android canvas or something?
Also inviting comments as to how idiotic this design decision was!
Try this:
WebSettings webSettings = webView.getSettings();
webSettings.setAllowContentAccess(true);
webSettings.setAppCacheEnabled(true);
webSettings.setDatabaseEnabled(true);
webSettings.setLoadWithOverviewMode(true);
webSettings.setUseWideViewPort(true);
webSettings.setDomStorageEnabled(true);
webSettings.setDatabaseEnabled(true);
webSettings.setCacheMode(WebSettings.LOAD_DEFAULT);
webSettings.setAllowContentAccess(true);
webSettings.setAllowFileAccessFromFileURLs(true);
webSettings.setJavaScriptEnabled(true);
Or you can use https://github.com/crosswalk-project . It has better graphics features. You can generate project via npm or (second preferred) use gradle dependency and use CrossWalkView as your simple WebView.
Also try one more extended webview lib: https://android-arsenal.com/details/1/4873
I have a problem with Android Web view.
The slider work fine with Apple but doesn't load on Android WebView.
Can anyone help? www.pgc-usa.net/ivynails
Thanks
I think I know. Web views in Android by default do not have JavaScript enabled. This is because there is someway it can do harm to the app. To enable it though it takes two lines
WebSettings webSettings = yourWebview.getSettings();
yourWebview.setJavaScriptEnabled(true);
You can also set it so that links that are clicked open in the web view. ( Otherwise they open in browser.) to add this you just add
yourWebview.setWebViewClient(new WebViewClient());
All that together will make it come to this:
WebView yourWebview = (WebView) findViewById(R.id.myWebview);
yourWebview.loadUrl("http://www.pgc-usa.net/ivynails");
WebSettings webSettings = yourWebviewgetSettings();
webSettings.setJavaScriptEnabled(true);
yourWebview.setWebViewClient(new WebViewClient());
You can find out more by visiting this page on the Android developer site by clicking this link.
I am trying to make an Android app display a website in a WebView, but only the website home page actually show content properly via the WebView, the other pages completely disregard the website styles and display content with a white background and blue default hyperlinks. I tested the same type of app on iOS and it works fine there. What can I do about it?
This is the method:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
WebView myWebView = (WebView) findViewById(R.id.webView);
myWebView.getSettings().setJavaScriptEnabled(true);
myWebView.setWebViewClient(new WebViewClient());
myWebView.loadUrl("http://www.awesomestories.com");
}
Settings should be set. Tricks Like this:
WebSettings settings = webview.getSettings();
settings.setBuiltInZoomControls(true);
settings.setPluginState(PluginState.ON);
settings.setJavaScriptEnabled(true);
settings.setSupportZoom(true);
If you have kept Single Column Setting in WebView remove it, it will work just perfect.
myWebView.getSettings().setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN);
If you have not kept Single Column setting and still its not working, then check that you have enabled JavaScript or not, if not then enable it.
myWebView.getSettings().setJavaScriptEnabled(true);
Android WebView requires you to explicitly enable javascript.
Styles in the page may be loaded via javascript, and generally websites don't tend to work good without it, so enabling it is important and might solve your problem in addition to that.
myWebView.getSettings().setJavaScriptEnabled(true);
I am using a webView to display some contents in my android app:
WebView webView = (WebView) rootView.findViewById(R.id.web_view);
WebSettings settings = webView.getSettings();
settings.setDefaultTextEncodingName("utf-8");
settings.setJavaScriptEnabled(true);
settings.setLoadsImagesAutomatically(true);
settings.setSupportZoom(false);
webView.loadUrl("about:blank");
webView.loadData(result.getHtmlContent(), "text/html; charset=UTF-8", "UTF-8");
This works perfectly in ICS and below, yet in JB and above the pages load correctly the first times (from two to five/six times generally). After that, the webView appears blank. Even after debugging, the code seems to run normally, it's just not displayed. The only way to see the page is to terminate the app and restart it, and it happens again.
Does anyone know how to fix this?
Why do you have the webView.loadUrl("about:blank") immediately before the loadData call? Does it help if you remove the about:blank load?
Also, 'not displayed' is pretty vague - is the content loaded but not rendering or does the page not get navigated to? Check what URLs your're getting from the WebViewClient.onPageStarted/onPageFinished callbacks. It might help if you call loadData from onPageFinished if url == "about:blank" if this is a navigation issue.
I used
webView.loadData(htmlContent, "text/html; charset=UTF-8",null);
for the versions greater than GINGERBREAD_MR1.
And
webViewLivraison.loadDataWithBaseURL("",htmlContent, "text/html", "UTF-8", "");
for the versions GINGERBREAD_MR1 and below. And its working fine for me.
Try this and let me know.
Try this clear for every time before the page load also try to clear the caches if u need.
WebSettings settings = webView.getSettings();
settings.setDefaultTextEncodingName("utf-8");
settings.setJavaScriptEnabled(true);
settings.setLoadsImagesAutomatically(true);
settings.setSupportZoom(false);
webView.setWebViewClient(new CustomWebClient());
webView.clearView();
// add if u need
webView.clearCache(true);
webView.loadData(result.getHtmlContent(), "text/html; charset=UTF-8", "UTF-8");
There are possible reasons causing "WebView goes blank after finish loading page":
If your WebView part defined in the layout xml file has dimensions like
android:layout_width="wrap_content"
or
android:layout_height="wrap_content"
Then after the page is loaded, the content is defined and WebView tries to "wrap" it, thus in some cases reduces the view's dimensions into 0dp and make your WebView invisible.
Solution: change all those into fill_parent
android:layout_width="fill_parent"
android:layout_height="fill_parent"
This may be caused by an SSL certification error. Try this:
public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
handler.proceed();
}
i tried to load the url ww.youtube.com on my app in a webview. but it cant be load completely. it loads just like below image. in the browser it loads comfortably. why? Any Idea?
image http://www.freeimagehosting.net/uploads/d7356dd8e1.png
the simple answer is to call the youtube app thats loaded on every phone with your webview. check out the code on http://fluxkore.com/index.php/android-apps/ to call the youtube app.....
Enable JavaScript! =)
myWebView = (WebView) findViewById(R.id.webview);
WebSettings webSettings = myWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
myWebView.loadUrl("http://www.youtube.com");
It might be a problem with WebViews - WebViews aren't fully fledged browsers, and have limited functionality. For example, the reference page specifically says that WebViews don't handle JavaScripts. If JavaScripts, Flash or something like that is required to properly load YouTube, then that could be why the WebView doesn't handle it properly.