blob: 240a54cdadaa7333d6f5c9982615752973007877 [file] [log] [blame]
page.title=Samples
page.tags="examples","code"
@jd:body
<p>Welcome to code samples for Android developers. Here you can browse sample code and learn how to
build different components for your applications. Use the categories on the left to browse the
available samples.</p>
<p>Each sample is a fully functioning Android app. You can browse the resources, source files and
see the overall project structure. You can copy and paste the code you need, and if you want to
share a link to a specific line you can double-click it to the get the URL.</p>
<h2>Import Samples from GitHub</h2>
<p>Android Studio provides easy access to import Android code samples from GitHub and is the
recommended method to retrieve Android code samples.</p>
<p>To import a code sample into Android Studio:<p>
<ol>
<li>In the Android Studio menu, select <strong>File &gt; Import Sample</strong> to open the
Import Sample wizard.</li>
<li>Select a sample to import and click <strong>Next</strong>.</li>
<li>Specify the application name and project location if different from the displayed settings.</li>
<li>Click <strong>Finish</strong>.
<p>The sample project opens in a new Android Studio project.</p></li>
</ol>
<p class="note">
<strong>Note:</strong> When starting Android Studio, you can also select <strong>Import an
Android code sample</strong> in the Welcome to Android Studio wizard to import a sample project
from GitHub as a new project.
</p>
<p>To view the Android code samples that you can import, see the
<a class="external-link" href="https://github.com/googlesamples/">Google Samples page</a> on GitHub.</p>
<h2>Download Samples</h2>
<p>Although importing samples from Android Studio is the recommended method, you can also use the
categories on the left to browse the available samples and learn how to build different components
for your applications.</p>
<p>If you want to download a complete project, just click on any source file in the project and
click the <strong>Download</strong> link in the upper right of the source page.</p>
<p>To import a downloaded project:<p>
<ol>
<li>Unpack the downloaded project package.</li>
<li>In <a href="{@docRoot}studio/index.html">Android Studio</a>, chose
<strong>File &gt; Import Project</strong> and select the root folder of the unpacked project.
<p>Android Studio may ask you to choose the type of project you are importing.
If this is the case, make sure to choose <strong>Import project from
external model</strong> and select the <strong>Gradle</strong> option.
</p>
</li>
</ol>
<p class="note">
<strong>Note:</strong> When starting Android Studio, you can also select <strong>Import
Non-Android Studio project</strong> in the Welcome to Android Studio wizard to import a
downloaded sample project.
</p>
<p class="note">
<strong>Note:</strong> At this time, the downloadable projects are designed for use with Gradle
and Android Studio.
</p>