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