1 page.title=Getting the Samples 2 3 @jd:body 4 5 <p>Sometimes, the best way to learn how things are done is to look at some 6 code.</p> 7 8 <p>To help you get started quickly, the Android SDK includes a variety of sample 9 code and tutorials that illustrate key concepts and techniques of Android 10 application development. For example, the samples show the structure of the 11 manifest file and the use of activities, services, resources, 12 intents, content providers, and permissions. They also show how to add 13 specialized capabilities to your apps, such as Bluetooth and Contacts 14 integration, multiple screens support, Live Wallpaper, and more. </p> 15 16 <p>The SDK provides the samples both as source code and as browseable HTML, as 17 described in the sections below. All of the samples included in the SDK are 18 licensed under the <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache 19 2.0 license</a>, so feel free to use any of the code in your own applications as 20 needed!</p> 21 22 <h3 id="downloading">Downloading the Sample Code</h3> 23 24 <p>The SDK sample code is available to you as a set of downloadable SDK 25 components, each of which contains the samples for a specific Android platform 26 version. Once you have installed the SDK, you can download one or more samples 27 component(s) into your SDK environment using the Android SDK and AVD Manager 28 tool, which is pre-installed in the SDK. </p> 29 30 <p>To download the samples, launch the Android SDK and AVD Manager tool and 31 select one of the samples components from the <strong>Available 32 Packages</strong> panel, for example "Samples for SDK API 7". Select 33 <strong>Install Selected</strong>, verify and accept the download, then select 34 <strong>Install Accepted</strong> to download the component into your SDK. If 35 you aren't familiar with the Android SDK and AVD Manager and how to launch or 36 use it, please read the <a href="{@docRoot}sdk/adding-components.html">Adding 37 SDK Components</a> document. </p> 38 39 <p>When the download is complete, you can find the samples sources on your 40 computer in this location:</p> 41 42 <p style="margin-left:2em"> 43 <code><em><sdk></em>/samples/android-<<em>level</em>>/</code> 44 </p> 45 46 <p>You can easily create new Android projects with the downloaded samples, modify them 47 if you'd like, and then run them on an emulator or device. </p> 48 49 <p>For example, if you are developing in Eclipse with the ADT Plugin, you can 50 create a project for the "API Demos" sample app by starting a new Android 51 Project, selecting "Create project from existing source", and then browsing to 52 the <code><em><sdk></em>/samples/android-<<em>level</em>>/ApiDemos</code> 53 directory (the <code>samples</code> directory for the platform version you are 54 using).</p> 55 56 <p>If you are not working in Eclipse, you can create a project for the API Demos 57 sample using the <code>android</code> tool, by executing this command:</p> 58 59 <pre class="no-pretty-print"> 60 android update project -s -n API Demos -t <em><target_ID></em> -p <<em>path</em>></em>samples/android-<<em>level</em>>/ApiDemos/ 61 </pre> 62 63 <h3 id="browsing">Browsing the Sample Code</h3> 64 65 <p>For your convenience, the SDK provides browseable source code for the latest 66 versions of the samples. You can use your browser to navigate through the 67 structure of each sample and look at the source code in each of its files. </p> 68 69 <p>To browse the samples, go to the <a 70 href="{@docRoot}resources/samples/index.html">List of Sample Apps</a> first. 71 From there you can read a short summary of each sample application and what 72 types of concepts, features, or APIs it includes. Then, use the links provided 73 to move through the directories and files of each sample. The browseable source 74 is generated from the same source code that is downloadable through the Android 75 SDK and AVD Manager, as described above. </p> 76 77 <p>The browseable samples files are available online, at the Android Developers 78 site only and are not included in the downloadable offline documentation. 79 Note that, although samples for several platform versions are available for 80 download, only the samples for the latest platform version are browseable online. 81 </p> 82 83 84 <h3 id="more">More Sample Code</h3> 85 86 <p>If you are looking for more sample code, check out 87 <a href="http://code.google.com/p/apps-for-android/">apps-for-android</a>, a 88 collection of open source applications that demonstrate various Android APIs.</p> 89 90 91