Downloading the Sample Code
The SDK sample code is available to you as a set of downloadable SDK components, each of which contains the samples for a specific Android platform version. Once you have installed the SDK, you can download one or more samples component(s) into your SDK environment using the Android SDK and AVD Manager tool, which is pre-installed in the SDK.
To download the samples, launch the Android SDK and AVD Manager tool and select one of the samples components from the
Available Packagespanel, for example "Samples for SDK API 7". Select
Install Selected, verify and accept the download, then select
Install Accepted to download the component into your SDK. If you aren't familiar with the Android SDK and AVD Manager and how to launch or use it, please read the
Adding SDK Components document.
When the download is complete, you can find the samples sources on your computer in this location:
/samples/android-<level>/
You can easily create new Android projects with the downloaded samples, modify them if you'd like, and then run them on an emulator or device.
For example, if you are developing in Eclipse with the ADT Plugin, you can create a project for the "API Demos" sample app by starting a new Android Project, selecting "Create project from existing source", and then browsing to the /samples/android-<level>/ApiDemos
directory (the samples
directory for the platform version you are using).
If you are not working in Eclipse, you can create a project for the API Demos sample using the android
tool, by executing this command:
android update project -s -n API Demos -t -p <path>samples/android-<level>/ApiDemos/