page.title=Sample Code @jd:body

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 {@code ApiDemos} in the {@code samples/} directory. To create the API Demos project using the {@code 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 may not yet be available in the SDK. To ensure that you have the latest versions of the samples, you can download the samples pack 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.
BusinessCard
An application that demonstrates how to launch the built-in contact picker from within an activity. This sample also uses reflection to ensure that the correct version of the contacts API is used, depending on which API level the application is running under.
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 {@link android.media.JetPlayer}.
Live Wallpaper
An application that demonstrates how to create a live wallpaper and bundle it in an application that users can install on their devices.
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.
SampleSyncAdapter
Demonstrates how an application can communicate with a cloud-based service and synchronize its data with data stored locally in a content provider. The sample uses two related parts of the Android framework — the account manager and the synchronization manager (through a sync adapter).
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.