Using Intents to Launch Other Applications

Initially, an application may only be launching activity classes defined within its own package. However, with the appropriate permissions, applications may also launch external activity classes in other applications.

There are well-defined intent actions for many common user tasks. For example, you can create intent actions to initiate applications such as the following:

► Launching the built-in web browser and supplying a URL address

► Launching the web browser and supplying a search string

► Launching the built-in Dialer application and supplying a phone number

► Launching the built-in Maps application and supplying a location

► Launching Google Street View and supplying a location

► Launching the built-in Camera application in still or video mode

► Launching a ringtone picker

► Recording a sound

Here is an example of how to create a simple intent with a predefined action (ACTION_VIEW) to launch the web browser with a specific URL:

Uri address = Uri.parse("http://www.perlgurl.org"); Intent surf = new Intent(Intent.ACTION_VIEW, address); startActivity(surf);

This example shows an intent that has been created with an action and some data. The action, in this case, is to view something. The data is a uniform resource identifier (URI), which identifies the location of the resource to view.

For this example, the browser's activity then starts and comes into foreground, causing the original calling activity to pause in the background. When the user finishes with the browser and clicks the Back button, the original activity resumes.

Applications may also create their own intent types and allow other applications to call them, allowing for tightly integrated application suites.

Did you Know?

The OpenIntents.org website keeps a list of intent actions at www.openintents.org/en/intentstable. This list includes those built into Android as well as those available from third-party applications.

0 0

Post a comment