Android WebView and WebGL

后端 未结 3 1069
醉话见心
醉话见心 2020-12-20 00:36

Android WebView: WebGL is not working on some devices

I use Webview in my android application. The task is to add WebGL interactive elements on the screen. Applicati

相关标签:
3条回答
  • 2020-12-20 00:40

    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());
    
    0 讨论(0)
  • 2020-12-20 00:46

    Check out this answer. It might be of some help. Otherwise, I would advise you to use the CrossWalk project.

    0 讨论(0)
  • 2020-12-20 01:03

    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();
    }
    
    0 讨论(0)
提交回复
热议问题