I cannot call android function from javascript

I just started to create a kind of Android application for Android, an application with WebView. As a first step, I tried calling the Android code function from JavaScript. But the application continues to crash while I am on it.

All I did was tweak the WebView, add a class that is used from JavaScript code, and then call the function from JavasScript.

Thanks in advance.

The android codes are as follows:

public class Grand_ride_androidActivity extends Activity {
    WebView mWebView;
...
   public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        mWebView = (WebView) findViewById(R.id.webview);
        mWebView.getSettings().setJavaScriptEnabled(true);


        mWebView.addJavascriptInterface(new JavaScriptInterface(this), "Android");
        mWebView.loadUrl(Config.url);
    }
}

public class JavaScriptInterface {
    Context mContext;

    JavaScriptInterface(Context c) {
        mContext = c;
    }

    public void ensureTracking(Integer rideId) {
        //do nothing
    }
}

And the HTML is as follows:

...
<body>

<script type="text/javascript">
//<![CDATA[
        Android.ensureTracking(97);
//]]>
</script><div>
        <p>You have checked in at 03:44PM</p>
        <a href="/rides/97/check_out">Check out</a>
</div>
</body>
0
source share
1 answer

I think you can only use primitive types and String, so makeTracking (Integer rideId) should be guaranteed to Tracking (int rideId).

+3
source

All Articles