There are many applications that can pre-packaged into the android platform that can be reused by custom built applications because of the power of the android design that is based on implicit intents.(See part 3 of this series for implicit intents).
Here we will explore how to invoke the pre-packaged applications from our own through implicit intents. Note that in none of the snippets below, we actually call the pre-packaged or system applications. We just declare intents and pass them to an activity while starting the activity through
method. However, for each of these intents, the android platform finds the most befitting activity and invokes the same:
1. Call a number
Intent callNumber = new Intent();
This will call the number 9440012345. For calling custom numbers, you could provide the user with a edit text field from which you can access the number and set it to the data above instead of a hard-coded number.
2. Browse the web for a given url:
Intent searchGivenText = new Intent(Intent.ACTION_WEB_SEARCH);
searchGivenText.putExtra(SearchManager.QUERY, "Android Examples);
This will invoke the Google search engine to search the string "Android Examples" and return the results to you. This too can be generalized to accept a string from the user and set to the intent before starting the activity.
3. View google maps for a given location
Intent searchAddress = new Intent(Intent.ACTION_VIEW,
This shows the location of Bangalore on Google Maps.
4. View Contacts on the phone
Intent contacts = new Intent();
I have created an Android eclipse project which showcases all of these examples by taking inputs from the end user. You can access the same here.
Updated on March 31 2010:
The above example uses Android SDK 1.5 From SDK 1.6 and above, the Contact.People class has been deprecated and we need to use the ContactsContract class. So the line in code
has to be replaced by
Here is the complete source code that has been tested with Android SDK 2.1
Source: Pre-Packaged Applications | Android Developer Tutorial (Part 4)