Android RSS Reader 2.0

12:55 PM , , 15 Comments

Well, its now 2013, and I have updated a version of this post - a long with a complete working application on GitHub - you can find that here it covers Android 3.0+ so includes fragments and parsing the RSS in an AsyncTask. Of course, you can still read this post and access the code for the pre-3.0 version!

Since posting a link to my simple RSS Reader for Android implemented using a custom SAX parser I have some questions regarding upgrading to handle images - I have previously posted on how to implement new tags in the feed that you want to handle (including nested tags) - but one question I received was regarding when images are just embedded in the text (e.g. not a specific image tag, but say as part of a description as HTML).

So, I have updated the code (uploaded, see the sidebar) - this time it parses the description text data to retrieve any Image links its pretty grim string manipulation, but it does the job!

As you can see, it now parses the image URL from the description and inserts it to the left of the feed item.
What did I change?

First I needed to change the Article class to parse the link. I updated the setDescription method to also check for IMAGE tags to parse, if any found then it would set the ImgLink member:

 public void setDescription(String description) {
  this.description = description;
  //parse description for any image or video links
  if (description.contains("<img ")){
   String img  = description.substring(description.indexOf("<img "));
   String cleanUp = img.substring(0, img.indexOf(">")+1);
   img = img.substring(img.indexOf("src=") + 5);
   int indexOf = img.indexOf("'");
   if (indexOf==-1){
    indexOf = img.indexOf("\"");
   img = img.substring(0, indexOf);
   this.description = this.description.replace(cleanUp, "");

I then also had to update the RssListAdapter class - this needed the necessary action to pull down the link based on our parsed URL and then inflate the ImageView in our row:
         if (jsonImageText.get("imageLink") != null){
          String url = (String) jsonImageText.get("imageLink");
                URL feedImage= new URL(url);
             HttpURLConnection conn= (HttpURLConnection)feedImage.openConnection();
                InputStream is = conn.getInputStream();
                Bitmap img = BitmapFactory.decodeStream(is);


  1. These blog articles are very helpful. How would one go about making the rss articles so that when they're clicked, they will open to a link or webview?

  2. Same question about Mike here. I tried to get position from the Json object, get the 'url' string, then pass it to intent, but I still didn't get it to work. Can you help? Thanks a lot

  3. hi. can you help me? i have some problems reading rss coincidentally all 2.0. the rest works very well.
    i have problem with rss

  4. Im guessing this will only return the first image of a post....

  5. Mike and Sony
    In RSSReader class add in buildJsonObject funciton:
    String urlLink = article.getUrl().toString();
    current.put("URLLink", urlLink);

    In RSSActivity Class add a listner for item click.

    In the end off onCreate function add:
    current.put("URLLink", urlLink);

    Also add the listner function inside onCreate function:
    OnItemClickListener itemListener = new OnItemClickListener() {

    public void onItemClick(AdapterView parent, View v, int position, long rowid) {

    JSONObject jsonURL = (JSONObject) parent.getItemAtPosition(position);

    //System.out.println("XXXX Link found!");
    String url = null;
    try {
    url = (String) jsonURL.get("URLLink");
    } catch (JSONException e) {
    // TODO Auto-generated catch block

    URL webURL = null;
    try {
    webURL = new URL(url);
    } catch (MalformedURLException e) {
    // TODO Auto-generated catch block

    Intent myIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(webURL.toString()));


    1. Can you please add the whole code to have a listener in ListView items ? What do you mean by" In the end off onCreate function add:
      current.put("URLLink", urlLink);" in RSSActivity class?

    2. please, that would be very nice!

  6. Thank you so much for this example!

  7. thank you so much for this brief explanation... but i was wondering, why the scroll function is kinda laggy? even in my samsung galaxy s2? and sometimes it's stop working and i must force close it...

    any suggestions?

  8. Hei, thanks for such a great tute. however, i'm getting an error message when changing the URL feed.

    i get an error :

    01-13 17:50:35.919: ERROR/RSS Handler IO(281): Too many redirects >> Too many redirects

    Here is my feed URL :

    thank you. :D

  9. Please when i open the app to view RSS feeds i have JSON Exception on every element on the ListView. Any idea please?

  10. I get the same error: JSON Exception!! Please help!!

  11. hi this code not working with url rss/format=atom10. can you help me

  12. Thank you very much
    I was looking for tutorial looks like this for two months
    but I have same problem when I want to change the feed url
    JSON Exception
    any help ?

  13. Thanks so much

    I face a problem when I try to get the description contain multip-lines. The result is only the first line. Could you help to advise this issue.