0% found this document useful (0 votes)
85 views8 pages

MC LAB Exno 9

The document describes the steps to develop an Android application that uses an RSS feed. It involves creating a new project in Android Studio, designing the layout with a list view, adding permissions to access the internet, parsing an RSS feed from a URL to extract headlines and links into arrays, displaying the headlines in the list view, and launching a browser when items are clicked. The application is implemented using AsyncTask to load the RSS feed in the background, and displays the headlines successfully.

Uploaded by

vanitha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
85 views8 pages

MC LAB Exno 9

The document describes the steps to develop an Android application that uses an RSS feed. It involves creating a new project in Android Studio, designing the layout with a list view, adding permissions to access the internet, parsing an RSS feed from a URL to extract headlines and links into arrays, displaying the headlines in the list view, and launching a browser when items are clicked. The application is implemented using AsyncTask to load the RSS feed in the background, and displays the headlines successfully.

Uploaded by

vanitha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

Ex .

No : 09

Date : Android Application that makes use of RSS Feed

Aim :
 To develop a Android Application that makes use of RSS Feed.

Procedure :

Step – 1 : Open Android Stdio and then click on File -> New -> New project.

Step – 2 : Then select the Minimum SDK as shown below and click Next.

Step – 3 : Then select the Empty Activity and click Next. 

Step – 4 : Click on app -> res -> layout -> activity_main.xml.

Step – 5 : Click on app -> java -> com.example.exno10 -> MainActivity.

Step – 6 : Display the result.

Step – 7 : Terminate the program.

Program :

Activity_main . xml

<?xml version="1.0" encoding="utf-8"?>


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="fill_parent"
     android:layout_height="fill_parent"
     android:orientation="vertical" >
 
     <ListView
         android:id="@+id/listView"
         android:layout_width="match_parent"
         android:layout_height="wrap_content" />
 
</LinearLayout>
        
AndroidManifest . xml

<?xml version="1.0" encoding="utf-8"?>


<manifest xmlns:android="http://schemas.android.com/apk/res/android"
     package="com.example.exno6" >
 
     <uses-permission android:name="android.permission.INTERNET"/>
 
     <application
         android:allowBackup="true"
         android:icon="@mipmap/ic_launcher"
         android:label="@string/app_name"
         android:supportsRtl="true"
         android:theme="@style/AppTheme" >
         <activity android:name=".MainActivity" >
            <intent-filter>
            <action android:name="android.intent.action.MAIN" />
 
            <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
         </activity>
     </application>
 
</manifest>

MainActivity . java

package com.example.exno6;

 
import android.app.ListActivity;
import android.content.Intent;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlPullParserFactory;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
 
public class MainActivity extends ListActivity
{
    
List headlines;
     List links;
 
     @Override
     protected void onCreate(Bundle savedInstanceState)
     {
         super.onCreate(savedInstanceState);
         new MyAsyncTask().execute();
     }
 
     class MyAsyncTask extends AsyncTask<Object,Void,ArrayAdapter>
     {
         @Override
         protected ArrayAdapter doInBackground(Object[] params)
         {
            headlines = new ArrayList();
            links = new ArrayList();
            try
            {
                URL url = new URL("https://codingconnect.net/feed");
                XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
                factory.setNamespaceAware(false);
                XmlPullParser xpp = factory.newPullParser();
 
                // We will get the XML from an input stream
                xpp.setInput(getInputStream(url), "UTF_8");
                boolean insideItem = false;
 
                // Returns the type of current event: START_TAG, END_TAG, etc..
                int eventType = xpp.getEventType();
                while (eventType != XmlPullParser.END_DOCUMENT)
                {
                    if (eventType == XmlPullParser.START_TAG)
                    {
                        if (xpp.getName().equalsIgnoreCase("item"))
                        {
                            insideItem = true;
                        }
                        else if (xpp.getName().equalsIgnoreCase("title"))
                        {
                            if (insideItem)
                                headlines.add(xpp.nextText()); //extract the headline
                        }
                        else if (xpp.getName().equalsIgnoreCase("link"))
                        {
                            if (insideItem)
                                links.add(xpp.nextText()); //extract the link of article
                        }
                    }
                    else if(eventType==XmlPullParser.END_TAG && xpp.getName().equalsIgnoreCase("item"))
                    {
                        insideItem=false;
                    }
                    eventType = xpp.next(); //move to next element
               
Output :
}
 
            }
            catch (MalformedURLException e)
            {
                e.printStackTrace();
            }
            catch (XmlPullParserException e)
            {
                e.printStackTrace();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return null;
         }
         protected void onPostExecute(ArrayAdapter adapter)
         {
            adapter = new ArrayAdapter(MainActivity.this, android.R.layout.simple_list_item_1, headlines);
            setListAdapter(adapter);
         }
     }
 
     @Override
     protected void onListItemClick(ListView l, View v, int position, long id)
     {
         Uri uri = Uri.parse((links.get(position)).toString());
         Intent intent = new Intent(Intent.ACTION_VIEW, uri);
         startActivity(intent);
     }
 
     public InputStream getInputStream(URL url)
     {
         try
         {
            return url.openConnection().getInputStream();
         }
         catch (IOException e)
         {
            return null;
         }
     }
}

Result :
 Thus Android Application that makes use of RSS Feed is developed and executed successfully..

You might also like