我想为hybridApp制作一个应用程序,但发生了一些错误。 “未捕获TypeError:window.HybridApp.setMessage不是函数错误” 我试图找到原因,但我不能。
proguard的
-keepattributes JavascriptInterface
-keep public class com.test.crosswalkdemo2$AndroidBridge
-keep public class * implements com.test.crosswalkdemo2$AndroidBridge
-keepclassmembers class com.test.crosswalkdemo2$AndroidBridge {
<methods>;
}
-keepclassmembers class * {
@android.webkit.JavascriptInterface <methods>;
}
主要
public class AndroidBridge {
@JavascriptInterface
public void setMessage(final String text) { // must be final
handler.post(new Runnable() {
public void run() {
mTextView.setText(text);
}
});
}
}
HTML
<script language="JavaScript">
function setMessage(arg) {
document.getElementById('textMessageFromApp').innerHTML = arg;
}
function sendMessage(msg){
window.HybridApp.setMessage(msg);
}
</script>
</head>
<body>
<h2>Hybrid App (WEB+APP)</h2>
<hr/>
<input type="text" id="textMessageFromWeb" value="Hello, Hybrid(WEB)!!"/>
<input type="button" value="Send" onclick="sendMessage(document.getElementById('textMessageFromWeb').value)"/>
请参阅我的代码和帮助。