An RSS feed is an XML-formatted file used to publish periodically updated syndicated information. An RSS feed may be parsed (that is, read and formatted) using an XML parser. Java-compatible parsers used to parse XML on Android include:
android.content.res.XmlResourceParser
is a pull parser- Simple API for XML (SAX) is found in the
org.xml.sax
package - Android ROME Feed Reader is Google’s RSS feed reader for Android
- Android Feed Reader is another Google RSS/Atom feed reader for Android
- Android-rss is a lightweight Android library for RSS 2.0 feeds
javax.xml.parsers.SAXParser
to parse an RSS feed in XML format. SAXParser is a standard choice because it is included with the Android APIs in the Android SDK. We'll set up the development environment, create a simple Android app and feed for demonstration purposes, and then use SAXParser to format the feed for Android. While some familiarity with Java application development is assumed, this tip is suitable for developers new to Java mobile development. Setting up the environment
Take the following steps to set up the development environment for this project:- Install the Eclipse IDE.
- Install the Android Development Tools (ADT) plugin for Eclipse. The ADT plugin for Eclipse provides a set of extensions to develop Android applications in Eclipse.
- Install Android 2.3 SDK platform. Android SDK provides tools for developing Android applications.
- Create an Android Virtual Device and set the Target environment as Android 2.3.3. API Level 10.
The Android project
We'll create an example Android project to receive the RSS feed.- In your Eclipse IDE select File-->New.
- In New select Android-->Android Project, then click Next.
- In the New Android Project window, specify a Project name (RSSFeed).
- Select Android Platform 2.3 API 10 for your Build Target.
- In Properties, specify an Application name (again, RSSFeed), and a Package name (android.rss).
- Select the checkbox: Create Activity, and specify the
Activity
class (RssFeed
). - Specify the minimum SDK version as 10 and click Next; or, if you've selected the Platform 3.0 API 11, then specify the minimum SDK Version as 11.
Activity
class creates a window for a UI. The resulting Android project will consist of the following files:
- An activity class (
RSSFeed
), which extendsActivity
. - A res/layout/main.xml file, which specifies the layout of the Android UI components.
- An AndroidManifest.xml file, which contains application configuration such as the package name, the main activity to launch when the Android application is started, application components, processes, permissions, and the minimum API level.
LinearLayout
and set android:orientation
as "vertical
." Our goal is to display the RSS feed as a text message, so add a TextView
element for the title of the RSS feed and specify android:text
as a Google RSS Feed. Add a TextView
element, with id "rss
" to display the RSS feed. Listing 1 shows the resulting main.xml.Original Source
0 comments:
Post a Comment