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

leojg
  • 1,156
  • 3
  • 16
  • 40
  • 1
    http://stackoverflow.com/questions/9000717/passing-and-returning-value-from-javascript-to-android – Techie Jan 24 '13 at 20:09
  • And, linked to in that other question: http://stackoverflow.com/questions/8982570/pass-and-return-the-values-from-javascript-and-android-and-use-as-a-phone-gap-pl – apsillers Jan 24 '13 at 20:31

1 Answers1

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.

Community
  • 1
  • 1
Nicklas Gnejs Eriksson
  • 3,395
  • 2
  • 21
  • 19