Flash&Flex - Project Management

Page 32

ANDROID IN ACTION

Table 1. Commonly employed URIs in Android

Type of information

URI data

Contact lookup

content://contacts/people

Map lookup/search

Geo:0,0?q=23+Route+206+Sta nhope+NJ

Browser launch to a speci�c website

http://www.google.com/

The data component of an Intent is expressed in the form of a URI and can be virtually any piece of information, such as a contact record, a web site location, or a reference to a media clip. Table 1 lists some URI examples. The IntentFilter defines the relationship between the Intent and the application. IntentFilters can be specific to the data portion of the Intent, the action portion, or both. IntentFilters also contain a field known as a category. The categor helps classify the action. For example, the category named CATEGORY_LAUNCHER instructs Android that the Activity containing this IntentFilter should be visible in the main application launcher or home screen. When an Intent is dispatched, the system evaluates the available Activitys, Services, and registered BroadcastReceivers (more on these next) and dispatches the Intent to the most appropriate recipient. Figure 2 depicts this relationship among Intents, IntentFilters, and BroadcastReceivers. IntentFilters are often defined in an application’s AndroidManifest.xml file with the <intent-filter> tag. The AndroidManfest.xml file is essentially an application

descriptor file. A common task on a mobile device is looking up a specific contact record for the purpose of initiating a call, sending an SMS (Short Message Service), or looking up a snail-mail address when you’re standing in line at the neighborhood pack-andship store. A user may desire to view a specific piece of information, say a contact record for user 1234. In this case, the action is ACTION_VIEW and the data is a specific contact record identifier. This is accomplished by creating an Intent with the action set to ACTION_ VIEW and a URI that represents the specific person of interest. Here’s an example of the URI for use with the android.content.Intent. ACTION_VIEW action: content://contacts/people/1234

Here’s an example of the URI for obtaining a list of all contacts: content://contacts/people

Here’s a snippet of code demonstrating the PICKing of a contact record: Intent pickIntent = new Intent(Intent.ACTION_PICK,Uri.parse („content://contacts/people”));

startActivity(pickIntent);

This Intent is evaluated and passed to the most appropriate handler. In this case, the recipient would

������������������������ ���������������������������

�������������������������� �����������������������

������������������������������������������

���������������������� �� ��������������������������������� �� ���������������������

�������������������������������������������������������� ������������������������������������������

������������������������������������������������������ ������������������������������������������ ����������������������� ���������

������������������������� ��������������������

����������������������

Figure 2. Intents are distributed to Android applications, which register themselves by way of the IntentFilter, typically in the AndroidManifest.xml �le

32

02/2010 (20)


Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.