Previous section   Next section

Mobile Phone Handheld Hardware Hardware Rick Rogers John Lombardo O'Reilly Media, Inc. O'Reilly Media Android Application Development, 1st Edition

6.1. Application Setup in the Manifest File

Like every other Android application, the best place to get a sense of how the application is strung together is the application's AndroidManifest.xml file. Let's take a look at part of the AndroidManifest.xml file for ApiDemos, near the beginning of the file:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.android.apis">

    <uses-permission android:name="android.permission.READ_CONTACTS" />
    <uses-permission android:name="android.permission.WRITE_CONTACTS" />
    <uses-permission android:name="android.permission.CAMERA" />
    <uses-permission android:name="android.permission.VIBRATE" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.INTERNET" />

    <application android:name="ApiDemosApplication"
            android:label="@string/activity_sample_code"
            android:icon="@drawable/app_sample_code" >

        <uses-library android:name="com.google.android.maps" />

        <activity android:name="ApiDemos">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>    

Here are some of the highlights of the code:

The ApiDemosApplication class, found in the top-level directory of the source code, extends the Application class and has two methods: onCreate and onTerminate. The onCreate method executes before any activities start. Application-level global variables should be defined and initialized by the onCreate method. It's also a good place to set up any application-level default values.

There are several subdirectories under samples/ApiDemos/src/com/example/android/apis, each corresponding to a high-level functional area of the Android API:


App

Examples of application-level constructs such as Activities, Alarms, Dialogs, and Services.


Content

Describes how to read assets from a file, from resources, and from an XML file.


Graphics

Many types of graphics examples, such as arcs bitmap manipulation, clipping, layers, and OpenGL.


Media

Examples of the MediaPlayer and the VideoView.


OS

Examples of how to invoke operating system services. As of this writing, it shows how to use the VIBRATOR_SERVICE and SENSOR_SERVICE.


Text

Cool text tricks. The "Linkify" demo shows how to use the autoLink attribute of the TextView to automatically set up links in text: the user clicks on a URL and the browser comes up, or clicks on a phone number and the dialer appears. The "LogTextBox" demo shows how to create a simple screen log with a LogTextBox View.


Views

All of the various Android views: buttons, text boxes, autocompletion, date widgets, etc. You can find the dozens of different Android GUI elements here, along with their many options.

          
      Previous section   Next section