Hello i am creating a Android Application. I do not like using Androids UI System and have elected to use the WebView for UI Design as it is easier for me coming from a HTML5 Background. I have tried platforms like Cordova and Phonegap but they dont give me exactly the control id like as i also have a Java background. So just to reiterate i am using the WebView for UI only.
That being said there is a small amount of JavaScript code i would like to run on the web view, namely, Network Calls. I have a network back-end using OkHttp and can make those connections fine! But i cannot get any data back in a way that would be friendly to my current knowledge of webview.
Here is my JavaScript function signature:
function makeRequest(method,url,data,callback){
... Code Here ...
}
And I would like to call it like this:
makeRequest("GET","http://www.example.com/",{
"key1" : "value1",
"key2" : "value2"
},(code,responseJSON) => {
... Handle Response...
});
So far on my Android/Java side i have this:
@JavascriptInterface
public void makeRequest(String method, String url, String data, ??? callback){
... Handle Request Java-side ...
}
When the request is handled id like to call the callback function some how. Like an EventListener or something, but i am stumped as to the Type '???' Should be, or how i would go about calling that function so that the JavaScript code can receive its callback and continue.
I already have One-Way code working through my JavaScriptInterface with webview. and JSON is no problem, as its converted to a string in the JS code, and GSON can parse and get what i need. Its just this callback that has me stumped!
Thank you in advance for any help :)