gpt4 book ai didi

java - Android Webview 不适用于 Android 4.4

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:04:53 24 4
gpt4 key购买 nike

我正在开发基于 Webview 的 Android 应用程序。在 Android 4.1 上一切正常,但在 4.4 上会抛出此错误。

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)

如果我取消注释这一行,它会工作但(逻辑上)不会显示任何内容

webview.loadUrl("file:///android_asset/html/index.html");

Webview 配置代码如下所示。

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

HTML代码正是

<!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>

Java-Javascript 接口(interface)是

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;
}
}

提前致谢

最佳答案

请检查新的 kitkat api WebView 功能是否已更改

http://developer.android.com/guide/webapps/migrating.html

关于java - Android Webview 不适用于 Android 4.4,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21437270/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com