G B
G B

Reputation: 3024

Android WebView and HTML5 Canvas

I have a simple HTML file with a canvas component, when I load it into the Android web browser, it shows everything, but when I try to load it from my application inside a WebView, nothing is displayed.

I tried to load the same file from a local web server, and it didn't work. What am I doing wrong?

Here the code:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mWebView = new WebView(this);
    setContentView(mWebView);
    mWebView.setWebChromeClient(new WebChromeClient());
}

@Override
protected void onDestroy() {
    super.onDestroy();
}

@Override
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);
}

@Override
protected void onResume() {
    super.onResume();
    mWebView.loadUrl("http://10.0.10.92:8000");
}

If the web page contains "normal" HTML, everything works. It just seems to be a problem with the canvas element.

Upvotes: 2

Views: 4031

Answers (2)

Harsh Dattani
Harsh Dattani

Reputation: 2129

Use WebChromeClient and enable JavaScript in your webview

myWebView.setWebChromeClient(chromeClient);
myWebView.getSettings().setJavaScriptEnabled(true);

Upvotes: 1

Moti Azu
Moti Azu

Reputation: 5442

Looks like you didn't enable javascript for the webview.

myWebView.getSettings().setJavaScriptEnabled(true);

Upvotes: 4

Related Questions