views:

23

answers:

1

Hi all,

I want a HTML/javascript application, running in a WebView, to make AJAX calls that are handled by the Java code. Ideal would be to just intercept the call (easy, just use shouldOverrideUrlLoading()) and 'return' some data. However, I don't find a way to 'return' a response to the WebView, other than calling a javascript function using loadUrl(). This will not work for me, as the HTML/js app is a drop-in application which I don't control. As far as the HTML/js app concerns, it just does an AJAX call and receives some data back.

Any thoughts on this?

Thanks a lot. Erik

A: 

In the end I used the method described in the question anyway;

I intercepted some specific requests (like foo://bar/get/1?callback=foobar), then parsed the URL and called a javascript callback function with the actual data. The callback function was defined in the query-part of the URL, so in the above example that would be foobar();

Calling that function was easy, just use yourWebView.loadUrl("javascript:foobar('somedata')");

Erik