appView.addJavascriptInterface() does not work on API 17

本文详细介绍了在Android API 17版本中使用PhoneGap JavaScript调用Java代码时遇到的错误,并提供了解决方案。通过修改Java类的初始化方式和确保JavaScript接口正确注册,可以成功在API 17上实现跨平台调用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

i am able to use java function from my phonegap java script function and android 2.2 but same code is not run on API 17. what should i have to do to call native java code on from java script in API 17.

i use this code in my java file

 objCustomNativeAccess = new CustomNativeAccess(this, appView);
            appView.addJavascriptInterface(objCustomNativeAccess,
                    "CustomNativeAccess");
    super.loadUrl("file:///android_asset/www/index.html");

my CustomNativeAccess class is

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

and in my java script i use this line to call this login function

 var value = window.CustomNativeAccess.login(email,pass);

so using this i successfully call this on api 2.2 but when i run this code on api 17 it give me error

Uncaught TypeError: Object [object Object] has no method 'login' at file:///android_asset/www/index.html:81

how i can i use this on api 17

轉自http://stackoverflow.com/questions/16353430/appview-addjavascriptinterface-does-not-work-on-api-17

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值