How to easily handle RSS Feeds on Android with RSS Parser

Important Notice: this article was first published on my website on August 16th, 2017. I’m migrating my blog to Medium so I want to have a reference to the old articles.

Today I want to talk about RSS-Parser, another library that I wrote. I wrote also a library that allows to handle data from YouTube. You can find out more on my previous post.

This library allows you to easily download an (or multiple) RSS Feed in order to display it in your application. For every article it is possible to download the following information:

  • Title
  • Author
  • Description
  • Content
  • Main Image
  • Link
  • Publication Date
  • Categories

Here you can find an example of feed.

The source code of the library is on Github together with a sample application that shows what you can do with the library.

Of course the library is available also on jCenter so you can easily add the dependency on Gradle.

dependencies {
compile 'com.prof.rssparser:rssparser:1.4.4'
}

Now, let’s give a look on how it works. First on all you need to create a new Parser object and next you can execute the Parser by calling the method execute(), that requires as parameter the URL of the RSS feed.

If the data are correctly retrieved you can handle them inside the OnTaskCompleted method. Here you have an ArrayList of Article and you can use it for example to populate a Recycler View. Instead if some bad things happened, you can take actions inside the onError method.

import com.prof.rssparser.Article;
import com.prof.rssparser.Parser;
//url of RSS feed
String urlString = "http://www.androidcentral.com/feed";
Parser parser = new Parser();
parser.execute(urlString);
parser.onFinish(new Parser.OnTaskCompleted() {
    @Override
public void onTaskCompleted(ArrayList<Article> list) {
      //what to do when the parsing is done
      //the Array List contains all article's data.
}
    @Override
public void onError() {
      //what to do in case of error
}
});

That’s all! Please let me know if you notice any bug or if you have any advice that can improve this library.