Richard
Richard

Reputation: 339

Android - Obtaining data from a website

I'm finding my way around Android and so far so good. My next big challenge is coming to grips with web services. I would like to build an app that reads data from a web site or database on web server and store the data in my app.

Basically, it will be an app that I build in conjunction with a news website that pulls their latest articles into the app. What I'm finding difficult is how to bridge the gap between my application and the data in the SQL Server database.

I'm familiar with building asp websites that read data from a database, but how would I do something similar with an app?

Do I ask the website to store the articles in an xml format? Or, is there another way that I can request a specific article and be provided with the content?

I hope I'm phrasing the question correctly and that someone can just guide me to the right way to approach this.

Thanks in advance.

Upvotes: 0

Views: 756

Answers (2)

Amokrane Chentir
Amokrane Chentir

Reputation: 30385

You can approach this problem from different perspectives.

The common solution is to build a Webservice that will bridge the gap between your mobile application and the data that remain in your server. I personnaly prefer to setup a Rails backend and thus have a RESTful API that will help me access my data. For instance, to retrieve the list of articles I could just request the following url: http://my_server_host/articles. So for the Webservice part you can have whatever you want: Rails, J2EE, .NET etc. And you can choose the model that fits your needs (REST, SOAP, XML-RPC etc.).

Then you will have to write a class that will contain all the necessary calls to the Webservice you have built. Basically, if your Webservice returns the results as an XML format you will have to:

  • Send the request to the appropriate URL. (See: HttpGet or HttpPost if you want to modify a resource).
  • Parse the XML returned. (In short, you can use SAX or DOM to parse your XML response and transform them to a business entity (an Article, a User etc.).)

This hopefully gives you a hint about a possible solution. By the way Google is your friend, but I will probably come back to add external links/resources to help you more.

Edit

Another possible solution that could work for you, since all you need is to retrieve some articles. Just setup a simple Wordpress blog for instance. Wordpress gives you an URL for the blog's RSS feed, all you will have to do is to parse that RSS feed (XML). There is a great article on the IBM website for parsing an RSS feed that you can find here. By the way, this solution is only possible if you want to save your articles on a Wordpress blog. But you got the point hopefully.

Upvotes: 1

Lukas Knuth
Lukas Knuth

Reputation: 25755

Reading your data form the Database on the Server would be bad practice. You'd have to open up some ports and that's defiantly not what you want (if you don't have root-access, you also can't).

For non-interactive content (what you want) you would use XML or JSON.

Upvotes: 1

Related Questions