In this tutorial, we’ll be discussing Android RSS Reader and develop an RSS Feed Reader app in android studio.

The Android RSS Feed Reader app would showcase Movie Reviews from two popular websites.

Android RSS Reader

RSS stands for Really Simple Syndication. Websites generally provide RSS Feeds for their content. It’s in XML format and is typically used to access the latest contents fed in the website.

An RSS Feed xml document looks like this:

channel is the root element used to hold the below-mentioned elements.
title is the title of the website.
link contains the url of the website
item element consists of contents of the website. Each item describes the title, url, publication date and description(body) of the respective content.

In our following Android Project, we’ll use DocumentBuilderFactory instance to parse the xml document.
We’ll be using HttpClient and jsoup jar library to fetch the XML feed contents of the websites in an AsyncTask.
We’ll be developing an application that fetches the movies reviews from two of the websites: Rediff.com and Cinemablend.com using their RSS Feed and display the items in the form of a ListView. Clicking any of the ListView would open its content inside a WebView. Let’s get started.

Android RSS Feed Reader Project Structure

android-rss-feed-reader-project-structure

The project consists of three activities.
The First contains two Buttons that’ll act as links to the RSS Feeds of the two websites.
The second would display the latest RSS Feeds containing the Movie Reviews in the form of a ListView.
The third would open up the link from any of the List Row selected in the previous activity and load the URL in a WebView.
We’ve imported the jsoup.jar in our libs folder.
We need to set useLibrary 'org.apache.http.legacy' in our android{} block in the build.gradle as shown below:

android-rss-feed-reader-build-gradle

This is done to allow HtttpClient and HttpUrlConnection classes to be imported in our activities.

Android RSS Reader Code

The code for the activity_main.xml layout class is given below:

The code for the MainActivity.java class is given below:

In this, we pass over the RSS Url links via Intents to the RSSFeedActivity.java class that we’ll see next.

The code for the activity_rss_feed.xml layout is given below:

The code for the RSSFeedActivity.java class which extends a ListActivity is given below.

In this, we instantiate an instance of RSSParser class.
Inside the LoadRSSFeedItems AsyncTask method we call getRSSFeedItems() to get the RSSItems from the URL which are then stored inside an ArrayList of rssItems. The RSSItems ArrayList is then eventually loaded into the ListView rows.

The code for the rss_item_list_row.xml layout is given below:

On ListView row click listener we pass the current item’s url to the next Activity in the key url. Before we look at the next activity let’s see the RSSItem.java and RSSParser.java classes.

DO NOT forget to add the Activities in the Manifest file.

RSSItem.java

RSSParser.java
This is responsible for parsing the xml feed document.

getRSSFeedItems() is what returns the RSSItem List to the RSSFeedActivity.java.

The code for the activity_browser.xml layout is given below.

The code for the BrowserActivity.java class is given below.

The url passed from the RSSFeedActivity.java Activity is loaded here.

DO NOT forget to add the Internet Permissions in your AndroidManifest.xml file.

The output of the above application in action is given below.
android rss feed reader app

This brings an end to this tutorial. You can download the Android RSSFeedTutorial from the link below.

By admin

Leave a Reply

%d bloggers like this: