I am making an app that conects to a server from where it needs to get a path wich will use after for upload files to that server.
In the app, there is a webview that display webpage with the options. When you touch/click in one button… lets say, “get url” it is suposed to send the url(a simple string value) from the server to the app.
In the app I was thinking that it could be something like this.
class JSInterface {
public void getUrl(String URL) {
MainActivity.doSomethingWithUrl(URL);
}
}
In the server side:
<html>
<head>
<script>
function sendUrl() {
Android.getUrl()
}
</script>
</head>
<body>
<input type="button" value="sendUrl" onClick="sendUrl()" />
</body>
</html>
In the js sendURL function is where I dont know what to do.
PD: The server backend is php
You should read about the addJavaScriptInterface method of the webView:
http://developer.android.com/reference/android/webkit/WebView.html#addJavascriptInterface%28java.lang.Object,%20java.lang.String%29
Some more reading here: Understanding Android's webview addjavascriptinterface
It shouldn’t be hard to find more information if you need it.