ContentProvider with WebService as source
Asked Answered
S

2

6

The scenario is the following:

  • I've got an android app that basically consists of a mapview.
  • This app queries various web services such as Foursquare or Wikipedia to obtain a list of locations and plot them into the map.

The question,

  • Does anybody know how to build a Content Provider where the data source is a web service (like the ones mentioned above) and not a db? It'd be great if you could point me in the right direction.

Thanks!

Skean answered 18/1, 2011 at 15:30 Comment(2)
I just want to do the same, but instead of directly querying the web service it'd be the content provider the one doing it. In this way, I could use external apps to connect to different web services.Skean
More options of ContentProviders to web services are mentioned at #4098186Wollis
C
1

I was looking for the same thing as you were and i got across DataDroid http://www.datadroidlib.com/. I think it's easier to use and it's a straightforward way to handle REST if your webservice is REST oriented.

Edit:

DataDroid is now marked as deprecated. They move to Robospice see https://github.com/stephanenicolas/robospice

Cassareep answered 8/2, 2013 at 12:30 Comment(0)
C
1

Does anybody know how to build a Content Provider where the data source is a web service (like the ones mentioned above) and not a db?

Take into account the following answer may be considered a rather old-fashioned 'manual' method.

You could build a content provider that queries the web service, and converts the obtained result into a cursor.

To query the web service you could use HttpClient and HttpGet request. You can find a tutorial on MyKong on how to do this. There are also some newer alternatives to do this.

While parsing the search result you get from the web service, you can build your own cursor with the MatrixCursor class by adding rows with addRow() for every individual result.

If you were to do this, make sure you always call your Content Provider through a background thread (i.e. using CursorLoader, AsyncTask, or another form of threading), otherwise your network operation would end up on the main UI thread.

Controversial answered 4/11, 2014 at 17:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.