24
Android Manifest File COMP 365 Android Development

COMP 365 Android Development. Every android application has a manifest file called AndroidManifest.xml Found in the Project folder Contains critical

Embed Size (px)

Citation preview

Android Manifest File

COMP 365Android Development

Android Manifest

Every android application has a manifest file called AndroidManifest.xml

Found in the Project folder Contains critical concerning the entire application

and acts as an identifier for numerous properties

Manifest Characteristics

Declares the Java package the application is identified by.

Declares each component of the Android application 1. Activity2. Service3. Broadcast Receiver4. Content Provider

Lists the permissions the application requires to prompt the user and declares permissions that other programs require to interact with itself.

Manifest Characteristics Cont. Declares the minimum level of Android API

required to run this application. Lists the libraries that the application must be

linked to. Declares which processes will host the

application components.

Manifest Structure

Structured similarly to other XML files in Android development.

Begins with the XML header, following with the element header <manifest> and numerous elements under it.

Under the element <application> is where you will find component declaration.

Manifest example

<manifest> <application>

<activity android:name= “com.example.androidpracticeproj.MainActivity” android:label= “@string/app_name” > <intent-filter>

<action android:name= “android.intent.action.MAIN" />  <category android:name= “android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application></manifest> Note: The java package is called com.example.androidpracticeproj. However, you can shorthand the package name like depicted below: <manifest package= “com.example.androidpracticeproj” >

<application … ><activity android:name= “.MainAcivity”… /></application>

</manifest>

Intents

An Intent is an action or operation to be performed.

Similar to Java Events in that they carry information and a specialized string constant for a particular action that needs to be performed.

Has two data structures1. Intent.action2. Intent.data

Intents are primarily used to send data between two app components.

Intent.action

The general action to be performed, contains a string constant that specifies what action needs to be performed.

Intent.data

Data to operate on, for example a person record in the contacts database, expressed as a URI. URI stands for Uniform Resource Identifier, which is like a URL but for a file system.

Intent Application

Intents are usually used in one of these three ways:1. Starting an Activity2. Starting a Service3. Deliver a broadcast

Starting an Activity

As described before, an Activity is a single screen in an application. This is done by passing a new instance of an Activity to an Intent to startActivity(). Here the Intent specifies which activity to start and any data required by the new Activity.

Start a Service

A service is a background program that can process without user input. To start a service, pass an Intent to startService(). Once again, the Intent carries the service and the data. You can also bind the service to a user interface using bindService().

Delivering Broadcasts

A broadcast is a message that an application can receive, and is broadcast when certain events occur, like the phone booting up, or being placed to charge. You can broadcast a broadcast by passing an Intent to sendBroadcast(), sendOrderedBroadcast(), or sendStickyBroadcast().

Supplementing Activities

You can easily integrate your Activity with Android functions by using the Intent object.

Numerous Intents will let you utilize numerous functions of Android, like Android's Camera, Contact list, Messaging, retrieving and sending text/pictures, and so on.

Intent Variations

Intent.ACTION_MAIN

Start as a main entry point, does not expect to receive data.

Intent.ACTION_VIEW

Data: URI for action to be performed on

Display data to the user. This Intent is very versatile as it

displays in different information depending on the uri input.

Ex. If used on a contact entry, it will display the contact entry.

Intent.ACTION_EDIT

Data: URI to be edited Gives explicit access to the data

provided. Edit functionality depends on the

URI and what kind of data is being edited.

Intent.ACTION_PICK

Data: URI representing a directory from which to pick data

Allows a user to pick from a data from the directory and returns it

Intent.ACTION_DIAL

Data: Dial the URI provided, brings up an empty caller if no URI

Dials a number in the dialer, but asks for permission before calling

Intent.ACTION_CALL

Data: Call the URI provided, brings up an empty caller if no URI

Calls a number- requires permissions in the manifest file

MediaStore.ACTION_[media]_CAPTURE

Works with both images and videos

MediaStore.ACTION_IMAGE_CAPTURE - Captures an image using the camera and returns it

MediaStore.ACTION_VIDEO_CAPTURE - Captures a video using the camera and returns it

Intent.ACTION_PICK

Data: URI representing the directory from which the user should select data

This allows the user to select a piece of data and then return it using the MIME type to specify which kind of data should be selected.

Intent.ACTION_SENDTO

Data: URI representing data to be sent

Sends data. For example, if the data is a

“mailto:” it will use the email application, if the data is a “sms”, it will use the messaging

application, and etc.