JavaScript接口浏览器不工作4.2.2 [英] JavaScript Interface to a Browser not working in 4.2.2
问题描述
我测试过我的JavaScript界面的Android 2.3,4.0,4.1设备工作完美
但在星系S4是4.2.2不工作
我试着打电话给我从index.html的原生界面
onload事件,但它说,对象不确定。
I had tested my javascript interface working perfectly in android 2.3,4.0,4.1 devices but not working in galaxy S4 which is 4.2.2 i tried calling my native interface from index.html onload but it says object undefined.
我打电话从浏览器这个功能。
i am calling this function from browser
window.onload = function() {
window.jsinterface.getSomeString("testing from index.html");
}
这行code在我的活动recieving数据
this line of code in my activity for recieving data
final class JavaScriptInterface {
JavaScriptInterface() {}
public void getSomeString(String data) {
Log.d("yahoo", "DAta" + data);
Toast.makeText(Testing.this, "getsomestring:"+data, Toast.LENGTH_SHORT).show();
}
}
对于除这个方法从浏览器发送数据的任何建议也将是对我有帮助。
或指导我该怎么做。
any suggestion for sending data from browser except this method would also be helpful for me. or guide me what to do.
推荐答案
如果你的的android:targetSdkVersion
设置为17或更高,则需要添加 @JavascriptInterface
注释 getSomeData()
,如描述<一个href=\"https://developer.android.com/reference/android/webkit/WebView.html#addJavascriptInterface%28java.lang.Object,%20java.lang.String%29\">in文档。
If your android:targetSdkVersion
is set to 17 or higher, you need to add the @JavascriptInterface
annotation to getSomeData()
, as is described in the documentation.
这篇关于JavaScript接口浏览器不工作4.2.2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!