我能够使用我的phonegap java脚本函数和android 2.2 中的java函数,但是相同的代码不在API 17上运行。我应该怎么做才能调用native从Java的Java脚本API中对代码17appView.addJavascriptInterface()不适用于API 17
我在Java文件中使用此代码
objCustomNativeAccess = new CustomNativeAccess(this, appView);
appView.addJavascriptInterface(objCustomNativeAccess,
"CustomNativeAccess");
super.loadUrl("file:///android_asset/www/index.html");
我CustomNativeAccess类是
public class CustomNativeAccess {
private WebView mAppView;
private DroidGap mGap;
/**
* Constructor
*
* @param gap
* @param view
*/
public CustomNativeAccess(DroidGap gap, WebView view) {
mAppView = view;
mGap = gap;
}
/**
* Get the device phone number
*
* @return
*/
public JSONObject login(String email, String password) {
JSONObject object = new JSONObject();
object.put("Login_Status", login_status);
object.put("date", dateString);
return object;
}
和在我的Java脚本我使用此行来调用这个登录功能
var value = window.CustomNativeAccess.login(email,pass);
,因此使用此我成功地把这种对API的2.2,但是当我运行API 17这段代码把它给我错误
遗漏的类型错误:对象的翻译:有没有方法“登录”的文件:///android_asset/www/index.html:81
我如何我使用这个API上17
可以使用不是问题的构造函数。 – gregory561 2013-08-07 12:47:07
no probs与构造函数,但它没有必要在这一点, – benka 2013-10-30 14:15:49
我可以证实,构造函数没有问题。条件是方法必须有注解** @ JavascriptInterface **并且是** public **。 – nacho4d 2016-06-22 07:04:35