Android WebView和WebGL [英] Android WebView and WebGL

查看:324
本文介绍了Android WebView和WebGL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Android WebView:WebGL在某些设备上不工作

Android WebView: WebGL is not working on some devices

我在Android应用程序中使用Webview.任务是在屏幕上添加WebGL交互元素. 应用程序具有minSdk v21. Google宣布他们在WebView v36中支持WebGL.我使用html5test.com页面和测试网页检查WebGL的状态.

I use Webview in my android application. The task is to add WebGL interactive elements on the screen. Application have minSdk v21. Google announced that they support WebGL in WebView v36. I check WebGL status with html5test.com page and my test web page.

我的测试设置: Google Nexus 6P-Android 6.0.1,webView v48-WebGL正常工作

My test setup: Google Nexus 6P - Android 6.0.1, webView v48 - WebGL OK works

Sony Xperia Z2-Android 5.1.1,webView v48-WebGL正常工作

Sony Xperia Z2 - Android 5.1.1, webView v48 - WebGL OK works

三星Galaxy Note 4-Android 5.1.1,webView v48-WebGL正常工作

Samsung Galaxy Note 4 - Android 5.1.1, webView v48 - WebGL OK works

三星Galaxy Tab S-Android 5.0.2,webView v48-WebGL FAILED黑屏

Samsung Galaxy Tab S - Android 5.0.2, webView v48 - WebGL FAILED blank screen

RKM V5 Android TV-Android 5.1.1,webView v39-WebGL FAILED黑屏

RKM V5 Android TV - Android 5.1.1, webView v39 - WebGL FAILED blank screen

我没有在android.webkit.WebView元素的Google Developer文档中看到有关的任何信息 有什么方法可以在所有设备上工作吗?

I do not see any info about in Google Developer documentation for android.webkit.WebView element Is there any way to make it possible to work on all devices?

我的webView初始化:

My webView initialization:

    mElementView = new WebView(mContext);
    mElementView.setVerticalScrollBarEnabled(scrollEnabled);
    mElementView.setHorizontalScrollBarEnabled(scrollEnabled);

    mElementView.getSettings().setJavaScriptEnabled(true);
    mElementView.getSettings().setAllowUniversalAccessFromFileURLs(true);
    mElementView.getSettings().setAllowFileAccessFromFileURLs(true);

更新:WebGL在所有设备上的Chrome浏览器中均可运行,但在Galaxy Tab和Android TV WebViews中无法运行

Update: WebGL works in Chrome browser on all devices, but fails in Galaxy Tab and Android TV webViews

推荐答案

后来,但我认为这对某人会有帮助. 在使用webView的活动中,在androidmanifests set:android:hardwareAccelerated="true"中进行设置. 我的webView看起来像这样:

Late but I think this will be helpful to someone. In your activity using webView, set this in androidmanifests set: android:hardwareAccelerated="true". And my webView looks like this:

 webView.getSettings().setJavaScriptEnabled(true);
    webView.getSettings().setAllowFileAccess(true);
    webView.getSettings().setPluginState(WebSettings.PluginState.ON);
    webView.getSettings().setDomStorageEnabled(true);
    webView.getSettings().setAllowContentAccess(true);
    webView.getSettings().setLoadsImagesAutomatically(true);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        webView.getSettings().setAllowFileAccessFromFileURLs(true);
    }
    webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);

    webView.setWebChromeClient(new WebChromeClient());

这篇关于Android WebView和WebGL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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