简体   繁体   English

Android WebView和WebGL

[英]Android WebView and WebGL

Android WebView: WebGL is not working on some devices Android WebView:WebGL无法在某些设备上运行

I use Webview in my android application. 我在我的Android应用程序中使用Webview。 The task is to add WebGL interactive elements on the screen. 任务是在屏幕上添加WebGL交互元素。 Application have minSdk v21. 应用程序有minSdk v21。 Google announced that they support WebGL in WebView v36. 谷歌宣布他们支持WebView v36中的WebGL。 I check WebGL status with html5test.com page and my test web page. 我用html5test.com页面和我的测试网页检查WebGL状态。

My test setup: Google Nexus 6P - Android 6.0.1, webView v48 - WebGL OK works 我的测试设置:谷歌Nexus 6P - Android 6.0.1,webView v48 - WebGL OK工作正常

Sony Xperia Z2 - Android 5.1.1, webView v48 - WebGL OK works 索尼Xperia Z2 - Android 5.1.1,webView v48 - WebGL OK工作正常

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

Samsung Galaxy Tab S - Android 5.0.2, webView v48 - WebGL FAILED blank screen 三星Galaxy Tab S - Android 5.0.2,webView v48 - WebGL FAILED空白屏幕

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

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? 我没有在Android开发者文档中看到有关android.webkit.WebView元素的任何信息有没有办法让它可以在所有设备上工作?

My webView initialization: 我的webView初始化:

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

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

Update: WebGL works in Chrome browser on all devices, but fails in Galaxy Tab and Android TV webViews 更新:WebGL适用于所有设备上的Chrome浏览器,但在Galaxy Tab和Android TV webViews中失败

Late but I think this will be helpful to someone. 迟到但我觉得这对某人有帮助。 In your activity using webView , set this in androidmanifests set: android:hardwareAccelerated="true" . 在使用webView的活动中,在androidmanifests中设置它: android:hardwareAccelerated="true" And my webView looks like this: 我的webView看起来像这样:

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

this coding working well. 这种编码效果很好。 try this 尝试这个

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.about);

    mToolbar = (Toolbar) findViewById(R.id.toolbar);
    TextView title=(TextView)findViewById(R.id.toolbar_title);
    title.setText(R.string.about);
    setSupportActionBar(mToolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    webView=(WebView)findViewById(R.id.webView);
    webView.setWebViewClient(new MyBrowser());
    webView.getSettings().setLoadsImagesAutomatically(true);
    webView.getSettings().setJavaScriptEnabled(true);
    webView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
    webView.loadUrl(url);
}
private class MyBrowser extends WebViewClient {
    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        view.loadUrl(url);
        return true;
    }
}
public boolean onOptionsItemSelected(MenuItem item)
{
    switch (item.getItemId()) {
        case android.R.id.home:
            Intent report = new Intent(About.this, MainActivity.class);
            startActivity(report);
            finish();
            break;
        default:
            break;
    }
    return false;
}
@Override
public void onBackPressed() {
    Intent intent=new Intent(About.this,MainActivity.class);
    startActivity(intent);
    super.onBackPressed();
}

Check out this answer. 看看这个答案。 It might be of some help. 它可能会有所帮助。 Otherwise, I would advise you to use the CrossWalk project. 否则,我建议您使用CrossWalk项目。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM