Sample Code

Sometimes, the best way to learn how things are done is to look at some code.

Here, you can browse the source of some sample Android applications. Also, each version of the Android platform available for the SDK includes a set of sample applications (which may vary between different versions of the platform). You can find the samples in your SDK at:

<sdk>/platforms/android-<version>/samples/

You can easily create new Android projects with these samples, modify them if you'd like, then run them on an emulator or device. For example, to create a project for the API Demos app from Eclipse, start a new Android Project, select "Create project from existing source", then select ApiDemos in the samples/ directory. To create the API Demos project using the android tool, execute:

android update project -s -n API Demos -t <target_ID> -p <path-to-platform>/samples/ApiDemos/

The pages below provide an overview of each sample application (available with most platforms) and allow you to view the source files in your browser.

Some of the samples in this listing are not yet available in the SDK. While we work to update the SDK, you can download the latest samples as a ZIP archive.

API Demos
A variety of small applications that demonstrate an extensive collection of framework topics.
Bluetooth Chat
An application for two-way text messaging over Bluetooth.
Contact Manager
An application that demonstrates how to query the system contacts provider using the ContactsContract API, as well as insert contacts into a specific account.
Home
A home screen replacement application.
JetBoy
A game that demonstrates the SONiVOX JET interactive music technology, with JetPlayer.
Lunar Lander
A classic Lunar Lander game.
Multiple Resolutions
A sample application that shows how to use resource directory qualifiers to provide different resources for different screen configurations.
Note Pad
An application for saving notes. Similar (but not identical) to the Notepad tutorial.
Searchable Dictionary
A sample application that demonstrates Android's search framework, including how to provide search suggestions for Quick Search Box.
Snake
An implementation of the classic game "Snake."
Soft Keyboard
An example of writing an input method for a software keyboard.
Wiktionary
An example of creating interactive widgets for display on the Android home screen.
Wiktionary (Simplified)
A simple Android home screen widgets example.

For more sample applications, check out apps-for-android, a collection of open source applications that demonstrate various Android APIs.