Does Android Webview Browsers Support HTML5 Features

Does android webview browsers support html5 features?

A WebView supports them, but you have to turn them on. I use the following code which turns on every features which are available. This is necessary because Application Caches for example are not supported on All Android-Versions:

    wv = (WebView) findViewById(R.id.webview);
WebSettings ws = wv.getSettings();

ws.setJavaScriptEnabled(true);
ws.setAllowFileAccess(true);

if (Build.VERSION.SDK_INT>=Build.VERSION_CODES.ECLAIR) {
try {
Log.d(TAG, "Enabling HTML5-Features");
Method m1 = WebSettings.class.getMethod("setDomStorageEnabled", new Class[]{Boolean.TYPE});
m1.invoke(ws, Boolean.TRUE);

Method m2 = WebSettings.class.getMethod("setDatabaseEnabled", new Class[]{Boolean.TYPE});
m2.invoke(ws, Boolean.TRUE);

Method m3 = WebSettings.class.getMethod("setDatabasePath", new Class[]{String.class});
m3.invoke(ws, "/data/data/" + getPackageName() + "/databases/");

Method m4 = WebSettings.class.getMethod("setAppCacheMaxSize", new Class[]{Long.TYPE});
m4.invoke(ws, 1024*1024*8);

Method m5 = WebSettings.class.getMethod("setAppCachePath", new Class[]{String.class});
m5.invoke(ws, "/data/data/" + getPackageName() + "/cache/");

Method m6 = WebSettings.class.getMethod("setAppCacheEnabled", new Class[]{Boolean.TYPE});
m6.invoke(ws, Boolean.TRUE);

Log.d(TAG, "Enabled HTML5-Features");
}
catch (NoSuchMethodException e) {
Log.e(TAG, "Reflection fail", e);
}
catch (InvocationTargetException e) {
Log.e(TAG, "Reflection fail", e);
}
catch (IllegalAccessException e) {
Log.e(TAG, "Reflection fail", e);
}
}

WebView and HTML5 video

It is possible to view a video element (video html5 tag) within a WebView, but I must say I had to deal with it for few days. These are the steps I had to follow so far:

  • Find a properly encoded video

  • When initializing the WebView, set the JavaScript, Plug-ins the WebViewClient and the WebChromeClient.

    url = new String("http://broken-links.com/tests/video/"); 
    mWebView = (WebView) findViewById(R.id.webview);
    mWebView.setWebChromeClient(chromeClient);
    mWebView.setWebViewClient(wvClient);
    mWebView.getSettings().setJavaScriptEnabled(true);
    mWebView.getSettings().setPluginState(PluginState.ON);
    mWebView.loadUrl(url);
  • Handle the onShowCustomView in the WebChromeClient object.

    @Override
    public void onShowCustomView(View view, CustomViewCallback callback) {
    super.onShowCustomView(view, callback);
    if (view instanceof FrameLayout){
    FrameLayout frame = (FrameLayout) view;
    if (frame.getFocusedChild() instanceof VideoView){
    VideoView video = (VideoView) frame.getFocusedChild();
    frame.removeView(video);
    a.setContentView(video);
    video.setOnCompletionListener(this);
    video.setOnErrorListener(this);
    video.start();
    }
    }
    }
  • Handle the onCompletion and the onError events for the video, in order to get back to the web view.

    public void onCompletion(MediaPlayer mp) {
    Log.d(TAG, "Video completo");
    a.setContentView(R.layout.main);
    WebView wb = (WebView) a.findViewById(R.id.webview);
    a.initWebView();
    }

But now I should say there are still an important issue. I can play it only once. The second time I click on the video dispatcher (either the poster or some play button), it does nothing.

I would also like the video to play inside the WebView frame, instead of opening the Media Player window, but this is for me a secondary issue.

Ttitanium webview and HTML5 application cache

Just in case someone else is running in the same problems that i was facing, here is what i've done. HTML5's application cache does not seem to work in the build-in browser of Android and with that the webviews. In Titanium there seems to be no way to control the webview as to enable the application cache.

The work around for me was to use Titanium and it's httpClient function (Titanium.Network.HTTPClient) to request the files (HTML, CSS, javascript) and store it in the local app filesystem (Titanium.Filesystem).

Run video from html5 Video tag in android

Android's WebView provides many HTML5 features, such as and geolocation, but those features are not enabled by default. Furthermore, some of the steps to enable those features.

Try this Html5WebView

it may help you.



Related Topics



Leave a reply



Submit