1

I have offline web page on android tablet.

Is it possible to write android service which will get data from web page when user insert data and submit it, and when android service receive data than it has to save it in text file or db.

Everything is in offline local mode.

tanasi
  • 1,804
  • 6
  • 37
  • 53

1 Answers1

3

You should be carful when using the word Service besides android. People might get a worng idea of what you're taliking about because it has a special meaning for android.

Because a local webpage will submit a post request to a certain URL and your device is actually not the webserver you will fail with that. But you can accomplish your task with a javascript/JSON bridge to your local HTML. See this post to see how.

The idea is to use a click handler which collects the needed data and returns it to the webview by the javascript bridge instead submiting the data to a from submit URL. From java side to WebView you can respond with an JSON object.

To accomplish this you need to have fundamental knowledge about HTML and javascript and understand the use of a WebView.

Community
  • 1
  • 1
Knickedi
  • 8,742
  • 3
  • 43
  • 45
  • I am new to Android programming. I need service which will save http post url from web browser. What I don't understand is moment when user press button on web form. In that moment android service need to receive data from browser. – tanasi Sep 26 '11 at 10:48
  • The posted link demonstrates how to do that with code examples. We can't help you that much as long we don't know how your data looks like. – Knickedi Sep 26 '11 at 11:00
  • It is not problem, I just don't understand how will android service to react on event, when there is no event. User just click on web form that's all. – tanasi Sep 26 '11 at 11:18
  • Well, since your webpage is local I thought that you can modify the actual HTML to avoid a from submit but react on the actual button click, collect the needed data, put it into a JSON object, pass it back to java by javascript bride and then react in your java code on that. – Knickedi Sep 26 '11 at 11:31
  • My question now is, how to pass data from JSON object to java with javascript bridge? – tanasi Sep 26 '11 at 12:31
  • (It has not to b e JSON actually, you can pass whatever you want to the bridge). Please see the posted example. It clearly shows how this works, there's nothing you could understand the wrong way. I wont't reply anymore as long as you didn't tried it on your own. – Knickedi Sep 26 '11 at 12:36