Android Webview not working on Android 4.4
18,628
Solution 1
please check new kitkat api web view functionallity has changed
http://developer.android.com/guide/webapps/migrating.html
Solution 2
Check with it.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
mWebView.evaluateJavascript("function myFunc(){"Your javascript code"};);", new ValueCallback<String>() {
@Override
public void onReceiveValue(final String dataResult) {
}
});
} else {
mWebView.loadUrl("function myFunc(){"Your javascript code"};);");
}
Author by
user3241778
Updated on July 19, 2022Comments
-
user3241778 almost 2 years
I am developing an Android application based on a Webview. All is working fine on Android 4.1 but on 4.4 it throws this errors.
01-29 11:16:03.075: E/eglCodecCommon(2179): glUtilsParamSize: unknow param 0x00000bd0 01-29 11:16:03.095: E/eglCodecCommon(2179): ** ERROR unknown type 0x10037 (glSizeof,72)
If I uncomment this line it' working but (logically) not showing anything
webview.loadUrl("file:///android_asset/html/index.html");
The Webview config code looks like this.
webview = new WebView(this); webview.clearCache(true); webview.clearHistory(); WebSettings webSettings = webview.getSettings(); webSettings.setJavaScriptEnabled(true); webSettings.setDomStorageEnabled(true); webview.setWebViewClient(new WebViewClient()); //webview.setWebChromeClient(new WebChromeClient()); webview.addJavascriptInterface(new JavaScriptInterface(this), "Android"); setContentView(webview); webview.loadUrl("file:///android_asset/html/index.html");
The HTML code is exactly
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0"/> <meta name="description" content=""> <meta name="author" content=""> <title>My Web App</title> <script src="../js/jquery.js"></script> <script src="../js/hammer.js"></script> <script src="../js/lightboxes.js"></script> <link href="../css/main.css" rel="stylesheet"> <link href="../css/lightboxes.css" rel="stylesheet"> <script type="text/javascript"> activeId = "contentOne"; passiveId = "contentTwo"; swiping = false; function changeElements() { $("#" + passiveId).css("display", "none"); $("#" + passiveId).css("-webkit-transition", "-webkit-transform 0s linear"); $("#" + passiveId).css("-webkit-transform", "translate(150%,0)"); setTimeout(function() { $("#" + passiveId).css("display", "block"); $("#" + passiveId).css("-webkit-transition", "-webkit-transform 0.25s ease-in-out"); swiping = false; }, 10); } function nextPhrase() { if (!swiping) { swiping = true; $("#" + activeId).css("-webkit-transform", "translate(-101%,0)"); $("#" + passiveId).css("-webkit-transform", "translate(2.5%,0)"); var result = Android.getPhrase(); document.getElementById(passiveId + "Text").textContent = result; tempId = activeId; activeId = passiveId; passiveId = tempId; setTimeout(changeElements, 600); } //$("#"+passiveId).css("-webkit-transition", "-webkit-transform 0.1s linear"); //$("#"+passiveId).css("-webkit-transform", "translate(-100%,0)"); //$("#"+passiveId).css("-webkit-transition", "-webkit-transform 0.6s ease-in-out"); //document.getElementById("next").style.backgroundColor="blue"; } function rel() { document.getElementById("next").style.backgroundColor = "#FFF"; } function changeColor(el) { document.getElementById("next").style.backgroundColor = "#EEE"; } </script> </head> <body> <div id="contentHeader"> Never I have ever ... </div> <div id="container"> <div id="contentOne"> <div id="contentOneText"> </div> </div> <div id="contentTwo"> <div id="contentTwoText"> </div> </div> </div> <div id="headNav"> <div class="navElement" id="next" > <div class="elName"> Next </div> </div> </div> <div id="proposalLightbox">sdfsdfasfasdf</div> <div id="fade"></div> <script> Hammer(document).on("dragleft", function(e) { nextPhrase(); }); document.getElementById('next').ontouchstart = function(eve) { nextPhrase(); document.getElementById("next").style.backgroundColor = "#EEE"; } document.getElementById('next').ontouchend = function(eve) { //alert() document.getElementById("next").style.backgroundColor = "#FFF"; } var result = Android.getPhrase(); document.getElementById(activeId + "Text").textContent = result; function testEcho(par) { alert(par); } function openProposeDialog(par) { showLightbox("proposalLightbox"); } document.getElementById('fade').ontouchstart = function(eve) { closeLightboxes(); } //nextPhrase(); </script> </body> </html>
And the Java-Javascript interface is
public class JavaScriptInterface { Context mContext; JavaScriptInterface(Context c) { mContext = c; } public String showToast(String toast) { Toast.makeText(mContext, toast, Toast.LENGTH_SHORT).show(); return toast; } public String getPhrase() { String phrase = ""; //phrase = dataHandler.getRandomPhrase(); return phrase; } }
Thanks a lot in advance
-
user3241778 over 10 yearsThanks a lot, but what base url should I use if my Apps name is NeverEver and the package is com.example.nevereversecond. If I use: view.loadDataWithBaseURL("nevereversecond://com.example.nevereversecond/", content, null, "UTF-8", null); I get the same error as the previous.
-
user3241778 over 10 yearsOkay now I have the exact Example application and get the exact same error, how could this be. Its from Google so I don't think that there is a error in their app.
-
gregko over 10 yearsIt seems that this is a bug in Android 4.4.2 emulator only. It happens with the emulator from the official Android SDK, and also for Genymotion emulators, based on it. Even a trivial app that displays a web view and shows any HTML code in it, displays this warning and scrolls very slowly. I tested this on one and only device with Android 4.4.2 that I have, and it did not show the bug.
-
rogerdpack over 6 yearsNB that both methods still work on kitkat, just
evaluateJavascript
is preferred because it's got a callback so is more easily asynchronous...