Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ContentProvider with WebService as source

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!

like image 686
Robert Paulson Avatar asked Jan 18 '11 15:01

Robert Paulson


2 Answers

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

like image 116
Kalem Avatar answered Sep 29 '22 21:09

Kalem


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.

like image 32
stilkin Avatar answered Sep 29 '22 19:09

stilkin