dejavu
dejavu

Reputation: 3254

Retrieve data from website in android app

How can we retrieve data from a website and parse it into a readable format in the Android application? This means I want to extract data from website and use it in my android application, formatted in my way. It could be any website.

Upvotes: 23

Views: 112914

Answers (4)

Zar E Ahmer
Zar E Ahmer

Reputation: 34360

Use this

DefaultHttpClient httpClient = new DefaultHttpClient();
HttpGet httpGet = new HttpGet("http://www.someplace.com");
ResponseHandler<String> resHandler = new BasicResponseHandler();
String page = httpClient.execute(httpGet, resHandler);

This can be used to grab the whole webpage as a string of html, i.e., "<html>...</html>"

Note You need to declare the following 'uses-permission' in the android manifest xml file... answer by @Squonk here

And also check this answer

Upvotes: 5

sunriser
sunriser

Reputation: 780

You can do the HTML parsing but it is not at all recommended instead ask the website owners to provide web services then you can parse that information.

Upvotes: 2

Kumar Bibek
Kumar Bibek

Reputation: 9117

Use the WebView. Simple!!

http://developer.android.com/reference/android/webkit/WebView.html

Upvotes: 0

Rasel
Rasel

Reputation: 15477

You can use jsoup to parse any kind of web page. Here you can find the jsoup library and full source code.

Here is an example: http://desicoding.blogspot.com/2011/03/how-to-parse-html-in-java-jsoup.html

To install in Eclipse:

  1. Right Click on project
  2. BuildPath
  3. Add External Archives
  4. select the .jar file

You can parse according to tag/parent/child very comfortably

Upvotes: 17

Related Questions