35

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.

Ovidiu Latcu
  • 68,451
  • 14
  • 71
  • 82

4 Answers4

15

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.

Community
  • 1
  • 1
TryTryAgain
  • 7,060
  • 10
  • 37
  • 81
  • 1
    Great articles. Thanks a lot :D – Ovidiu Latcu Mar 19 '12 at 07:49
  • The link for the article is broken. – Raanan Apr 19 '13 at 12:32
  • @Raanan thanks for pointing that out! It seems all content for that blog blew up. I've added an archive.org copy of it, works now. Thanks again. – TryTryAgain Apr 19 '13 at 17:47
  • @TryTryAgain sorry to say, but still broken – Itai Hanski Aug 12 '13 at 16:40
  • @ItaiHanski I assume you're talking about the only link which is not a Stack Overflow link? and, it is not broken, it is a web archive link...working as expected: http://web.archive.org/web/20120311012317/http://www.erikyuzwa.com/mobile/5-reality-checks-every-team-needs-before-working-on-android-webkit-plus-1-more/ – TryTryAgain Aug 12 '13 at 17:00
9

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

Alp Altunel
  • 2,588
  • 1
  • 19
  • 25
Vatsal Desai
  • 161
  • 2
  • 11
8

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

Brian Mains
  • 49,697
  • 35
  • 139
  • 249
ondoteam
  • 203
  • 3
  • 6
  • Webview is restricted? how does setting the `WebChromeClient` improve the browsing experience? it is used just for handling JavaScript dialogs, favicons, titles, progress etc. I don't think this impacts if a webpage is loaded or not in the `WebView`. – Ovidiu Latcu Jan 25 '12 at 08:12
  • 1
    Hello. Can I have an example URL to work with? My english is not very good, maybe "restricted" is not the best word. I mean that WebView by default is intended to show basic HTML and interact with your application but, for example, you can tweak it to show FLASH using setPluginsEnabled(). By the way I always use local resources with WebView. – ondoteam Jan 25 '12 at 11:39
1

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.

Community
  • 1
  • 1
bytebiscuit
  • 3,264
  • 10
  • 31
  • 46