ContentProvider with WebService as a source

The scenario is as follows:

  • I have an android app that basically consists of a map.
  • This application requests various web services such as Foursquare or Wikipedia to get a list of places and map them.

Question,

  • Does anyone know how to create a content provider where the data source is a web service (like the one mentioned above) and not db? It would be great if you could point me in the right direction.

Thanks!

+4
source share
2 answers

I was looking for the same as you, and I went through DataDroid http://www.datadroidlib.com/ . I find this easier to use and an easy way to handle REST if your web service is REST oriented.

Edit:

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

+1
source

Does anyone know how to create a content provider where the data source is a web service (like the one mentioned above) and not db?

Consider the following answer can be considered a fairly old-fashioned "manual" method.

You can create a content provider that requests a web service and converts the result to a cursor.

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

When analyzing search results retrieved from a web service, you can create your own cursor using the MatrixCursor class by adding rows with addRow () for each individual result.

If you must do this, make sure you always invoke your content provider through a background thread (i.e. using CursorLoader , AsyncTask or some other form of streaming), otherwise your network operation will end in the main user interface thread.

+1
source

Source: https://habr.com/ru/post/1336009/


All Articles