0

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

2

1 Answer 1

0

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.