There is a web page that contains Flash content that I need to load into a WebView. I have tried with these settings:
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.getSettings().setPluginState(WebSettings.PluginState.ON);
mWebView.loadUrl(URL);
However the flash portion of the site never loads, it just stays a big white space. The same exact site Flash content and all loads perfectly in the stock browser. Is there something I am missing to get WebView to show Flash content?
Edit: Does WebView.refreshPlugins(boolean reloadPages) have anything to do with it? I have tried putting this in various spots but still no luck.
If you are using Android 3.0 or greater you may need to add android:hardwareAccelerated="true" to the application (or activity depending on where you might have WebViews) attributes in the manifest, I was caught out by this recently.
Related
I have developed an application in unity then I export it to WebGl then I have created a web page. When I preview the page on Android's Chrome browser there is no any problem, It shows the page in high quality however when I open the page in android WebView quality of graphics dramatically decreases. I have tested the same application on Android 7,8 and 9 but there is no difference between versions. I have tried hardwareAccelerated but the problem is already present. Is it possible to get same quality in WebView like it is in Chrome?
You can give a try to Chrome custom tabs. They are far more performant than a webview and they give to users a seamless in-app user experience.
Unfortunately webview lacks a lot of features of the common browsers and it's not the best choice to display complex web pages.
An Android app uses a WebView to display a Facebook Like Box. On 4.1.2 and 4.3 the page appears correctly when the following code is used.
String url = "https://www.facebook.com/plugins/likebox.php?href=https%3A%2F%2Fwww.facebook.com%2FGoogle&width&height=395&colorscheme=light&show_faces=false&header=false&stream=true&show_border=false";
WebView webview = (WebView) findViewById(R.id.web_content);
webview.getSettings().setJavaScriptEnabled(true);
webview.setWebChromeClient(new WebChromeClient());
webview.setWebViewClient(new WebViewClient());
webview.loadUrl(url);
On 4.4.2 the page looks good in the full-on Chrome app; however, the behaviour is not good when loaded in the WebView as coded above. There is a brief flash of a fully-rendered page then the WebView goes totally white. Nothing is visible and scrolling does nothing.
I have used chrome://inspect to watch the page as it loads, but it doesn't support showing network requests. The output of running document.location.href; at the console is about:blank, though, which is a clue.
Some ideas I've tried based on various threads:
Disabling hardware acceleration
Using webview.setLayerType(View.LAYER_TYPE_SOFTWARE, null)
Using android:hardwareAccelerated="false" in AndroidManifest.xml
Disabling JavaScript
This can't work because the Like Box requires JS to display at all
Some methods on webview.getSettings()
.setSupportZoom(true), .setSupportZoom(false)
.setUseWideViewPort(true), .setUseWideViewPort(false)
.setLoadWithOverviewMode(true), .setLoadWithOverviewMode(false)
Running custom CSS after the page is loaded to set a white background
I make sure it runs by creating an alert() directly afterward
At this point I may have to resort to starting an intent when running in 4.4 so the page is loaded by the browser in that case, but I would prefer to find a fix for the blank WebView. Are there any other settings I can tweak?
The above doesn't repro for me on 4.4
I have used chrome://inspect to watch the page as it loads, but it doesn't support showing network requests.
It totally does support showing network requests. Try this - in your app comment out loading the URL, just new the WebView up. Connect via DevTools and type
window.location = 'https://....';
The output of running document.location.href; at the console is about:blank, though, which is a clue.
Sounds like this is it. I'm not sure what the HTML/JS you end up loading does, maybe the JS tries to navigate to some weird URL? Try setting a WebViewClient that logs all shouldOverrideUrlLoading calls and see if you're getting a non-http(s) URL there. Try returning true for that URL.
Is there a certified way of enabling flash in a webview? I have a Samsung Galaxy S3 with ICS installed. flash works in my normal browser(the default browser that says Internet on the icon). I made an app which has webview in its layout. I load the same page in this webview and flash doesn't work. I tried adding the following line in onCreate of my main activity:
WebView webView1=(WebView)findViewById(...)
webView1.getSettings().setPluginState(WebView.PluginState.ON);
but doesn't work. I also tried using setPluginsEnabled(deprecated) but that also didn't work. Also, I set
android:hardwareAccelerated="true"
in menifest file in the application tag. But it still doesn't work.
So has anyone made it work? Please help.
Could it be a problem related to Javascript not being enabled on the webview?
myWebView.getSettings().setJavaScriptEnabled(true);
I had forgotten to enable javascript. Did that and it worked like a charm.
I've experienced a LOT of strange behaviours with using WebView in Android and I'm wondering why there are so many diffrences between the WebView and the Browserinstalled on each phone?
As an example, I've developed some applications that had to display HTML content, which contained either jquery-mobile, flash,javascript, YouTube embedded and so on. So I had a lot of problems with displaying this pages inside WebViews. Either they wouldn't get displayed at all, just blank, either the videos won't play and so on. And the strange thing is that they work properly if opened in the Browser installed on the phone. I had JavaScript enabled, I tried diffrent WebSettings, I had set the WebChromeClient and WebViewClient looking for javascript errors... but nothing worked.
So I got to the conclusion that the WebView component is completely different from the Browser application installed on the phones. I'm thinking that every manufacturer makes their own Browser to support as many as possible pages, and the WebView remains the standard one, included in the Android SDK.
Am I right? Or there is another reasons/explanation for this?
Thanks.
EDIT: Everything that #ondoteam has suggested was enabled and set at the time being. I no longer have the references to that websites, which anyway were internal.
This article outlines your speculation about stock browser differences between manufacturers, that absolutely is true: 5 reality checks every team needs before working on Android webkit
...which does cause trouble and mysterious/difficult to diagnose/solve problems.
As far as your issues with your WebView implementation:
Version of jquery-mobile may be an issue jquery-mobile loaded into an android WebView if you are using jquery.mobile-1.0.1.min.js you may want to try the uncompressed jquery.mobile-1.0.1.js
And Flash :-/ Good luck:
Screen blinking when using a webview with flash
Flash in WebView not working on Android 3.2
Flash video not displaying in WebView for Android 3.0.1
For loading SWF:
Load an SWF into a WebView
loading flash files (.swf) webview in android
Good luck with that, seems like a lot of variables with devices, Android versions, etc. And will take persistence with trial/error.
The stock browser and WebView differs .Using all the tweaks like
WebView browser;
browser.clearFormData();
browser.clearHistory();
browser.clearCache(true);
browser.getSettings().setAppCacheEnabled(true);
browser.getSettings().setDatabaseEnabled(true);
browser.getSettings().setDomStorageEnabled(true);
browser.setWebChromeClient(new WebChromeClient());
still it does not load high resolution images properly which is being loaded perfectly well by the android browser.
Only part of the image can be visible on the webview screen which appears fully on normal android browser.
This behavior is observed with latest Android 4X SDK as well.
Which means android default browser significantly tweaks the webkit/webview code to show any url
WebView by default is restricted. You should call setWebChromeClient and family to have a decent browsing experience. In addition, don't forget setJavaScriptEnabled() and other similar stuff. Sorry for my brevity... I think that you don't need examples.
http://developer.android.com/reference/android/webkit/WebView.html
have you checked this question : jquery-mobile loaded into an android WebView
it might be that you're using the wrong libraries. Just check in any case.
I am testing on a Xoom device, running OS 3.2. The project is built (in Eclipse) using the 3.1 library.
I have the latest version of flash installed, and embedded flash plays fine in my tablet's browser.
If I create an activity like this:
WebView browser = (WebView) findViewById(R.id.browserView);
browser .getSettings().setJavaScriptEnabled(true);
browser .getSettings().setPluginsEnabled(true);
browser .loadUrl("http://m.kongregate.com/games/Jiggmin/the-game-of-disorientation-mobile");
Then I hear the sound playing for the flash, but it shows up as a white box.
Similarly, any other page with embedded flash has the same problem. I've also tried making a string containing static HTML content, and loading that into the browser... but it has the same problem.
I've read every solution I could find online, from setting the view to invisible until the onPageFinish event is called, to extending the WebView class, and paining over it. I've tried reflection, to call hidden properties on the WebView's settings for enabling flash, etc. Nothing works.
Please help!
Thanks,
Mat
You can find my answer here :
Try to build your application with the latest android Api ( http://developer.android.com/guide/practices/optimizing-for-3.0.html#Upgrading ),
and activate hardware acceleration (same link, just a little below) on
your activity that need to display flash.