android webview 浏览器是否支持 html5 功能? [英] Does android webview browsers support html5 features?

查看:22
本文介绍了android webview 浏览器是否支持 html5 功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有基于 HTML5 的 Web 应用程序,我希望它与 WebView 集成,那么 android webview 浏览器是否支持 html5 功能?

I have HTML5 based web application i want it to integrate with WebView ,So does android webview browsers support html5 features?

推荐答案

WebView 支持它们,但你必须打开它们.我使用以下代码打开每个可用的功能.这是必要的,因为所有 Android 版本都不支持例如应用程序缓存:

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);
        }
    }

这篇关于android webview 浏览器是否支持 html5 功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆