code-reader
code-reader

Reputation: 33

Android webview can't draw canvas after chrome updated to 76+

My webview has drawing functionality inside a canvas which was working fine. But after upgradation of Chrome it stopped drawing inside canvas. I have a work around, by setting hardware acceleration true it works perfectly, but issue is my app's memory consumption increased rapidly. Is there any solution of this problem?

I am using Cordova for cross platform.

Upvotes: 0

Views: 4448

Answers (1)

vinicius.stutz
vinicius.stutz

Reputation: 31

Well, I don't know about Cordova, but I think this can also help you. I found that the key to solving the HTML5 canvas issue in Android webview is within AndroidManifest.xml. What did I have to do? I kept the strategy of using a hybrid (custom) webview, because as I develop in Xamarin Forms for both iOS and Android, I needed the same solution on both platforms. On Android I did:

// Java (or similar [laughs])
// Enable hardware acceleration using code (>= level 19)
if (Build.VERSION.SDK_INT >= 19) {
    yourWebviewObj.setLayerType(View.LAYER_TYPE_HARDWARE, null);
} else {
    yourWebviewObj.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
}

yourSettingsObj.setRenderPriority(WebSettings.RenderPriority.HIGH);
yourSettingsObj.setCacheMode(WebSettings.LOAD_NO_CACHE);
// Xamarin for Android
// Enable hardware acceleration using code (>= level 19)
if (Build.VERSION.SdkInt >= 19)
{
    yourWebviewObj.SetLayerType (LayerType.Hardware, null);
}
else
{
    yourWebviewObj.SetLayerType (LayerType.Software, null);
}

yourWebviewObj.Settings.SetRenderPriority(WebSettings.RenderPriority.High);
yourWebviewObj.Settings.CacheMode = CacheModes.NoCache;

And finally, within AndroidManifest.xml find for android:handwareAccelerated="false" and you can change the value from false to true. This tip (additionally) works for both the Java universe and Xamarin.

Had another person with the same problem at Android WebView with layer_type_software not showing HTML5 canvas content where I also posted the same solution. Sorry if my help was not enough, but today I develop applications using Xamarin. Anyway I believe that following this path will help you.

Upvotes: 3

Related Questions