Android Tutorials for Beginner Part-4(Android Pre-Packed applications)
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 startActivity() 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();
callNumber.setAction(android.content.Intent.ACTION_CALL);
callNumber.setData(Uri.parse("tel:9440012345"));
startActivity(callNumber);
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);
startActivity(searchGivenText);
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,
Uri.parse("geo:0,0?q=Bangalore"));
startActivity(searchAddress);
This shows the location of Bangalore on Google Maps.
4. View Contacts on the phone
Intent contacts = new Intent();
contacts.setAction(android.content.Intent.ACTION_VIEW);
contacts.setData(People.CONTENT_URI);
startActivity(contacts);
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.
Showing posts with label Android sample code. Show all posts
Showing posts with label Android sample code. Show all posts
Android Sample code
Android Sample code
Sometimes, the best way to learn how things are done is to just look at some code. So here we've provided links to let you browse the source of some sample Android applications included in the Android SDK.
The SDK includes a full set of sample applications for each Android platform version in the SDK. You can find the sample applications for each platform version in this location:
/platforms/android-/samples/
You can easily add these applications as projects in your development environment, so that you can modify them and watch them execute.
API Demos
A variety of small applications that demonstrate simple views and widgets.
Lunar Lander
A classic Lunar Lander game.
Note Pad
An application for saving notes. Similar (but not identical) to the Notepad tutorial.
Sometimes, the best way to learn how things are done is to just look at some code. So here we've provided links to let you browse the source of some sample Android applications included in the Android SDK.
The SDK includes a full set of sample applications for each Android platform version in the SDK. You can find the sample applications for each platform version in this location:
You can easily add these applications as projects in your development environment, so that you can modify them and watch them execute.
API Demos
A variety of small applications that demonstrate simple views and widgets.
Lunar Lander
A classic Lunar Lander game.
Note Pad
An application for saving notes. Similar (but not identical) to the Notepad tutorial.
Subscribe to:
Posts (Atom)