Android WebView 和 WebGL [英] Android WebView and 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
Samsung Galaxy Note 4 - Android 5.1.1, webView v48 - WebGL OK 工作
Samsung Galaxy Note 4 - Android 5.1.1, webView v48 - WebGL OK works
Samsung 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
我在 Google Developer 文档中没有看到有关 android.webkit.WebView 元素的任何信息有什么办法可以在所有设备上工作吗?
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 集中设置: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屋!