Home | History | Annotate | Download | only in samples
      1 page.title=Samples
      2 page.tags="examples","code"
      3 
      4 @jd:body
      5 
      6 
      7 <p>Welcome to code samples for Android developers. Here you can browse sample code and learn how to
      8 build different components for your applications. Use the categories on the left to browse the
      9 available samples.</p>
     10 
     11 <p>Each sample is a fully functioning Android app. You can browse the resources, source files and
     12 see the overall project structure. You can copy and paste the code you need, and if you want to
     13 share a link to a specific line you can double-click it to the get the URL.</p>
     14 
     15 
     16 <h2>Import Samples from GitHub</h2>
     17 
     18 <p>Android Studio provides easy access to import Android code samples from GitHub and is the
     19 recommended method to retrieve Android code samples.</p>
     20 
     21 <p>To import a code sample into Android Studio:<p>
     22 
     23   <ol>
     24     <li>In the Android Studio menu, select <strong>File &gt; Import Sample</strong> to open the
     25     Import Sample wizard.</li>
     26     <li>Select a sample to import and click <strong>Next</strong>.</li>
     27     <li>Specify the application name and project location if different from the displayed settings.</li>
     28     <li>Click <strong>Finish</strong>.
     29       <p>The sample project opens in a new Android Studio project.</p></li>
     30   </ol>
     31 
     32 <p class="note">
     33   <strong>Note:</strong> When starting Android Studio, you can also select <strong>Import an
     34   Android code sample</strong> in the Welcome to Android Studio wizard to import a sample project
     35   from GitHub as a new project.
     36 </p>
     37 
     38 <p>To view the Android code samples that you can import, see the
     39 <a class="external-link" href="https://github.com/googlesamples/">Google Samples page</a> on GitHub.</p>
     40 
     41 <h2>Download Samples</h2>
     42 
     43 <p>Although importing samples from Android Studio is the recommended method, you can also use the
     44 categories on the left to browse the available samples and learn how to build different components
     45 for your applications.</p>
     46 
     47 <p>If you want to download a complete project, just click on any source file in the project and
     48   click the <strong>Download</strong> link in the upper right of the source page.</p>
     49 
     50 <p>To import a downloaded project:<p>
     51 
     52   <ol>
     53     <li>Unpack the downloaded project package.</li>
     54     <li>In <a href="{@docRoot}studio/index.html">Android Studio</a>, chose
     55     <strong>File &gt; Import Project</strong> and select the root folder of the unpacked project.
     56       <p>Android Studio may ask you to choose the type of project you are importing.
     57         If this is the case, make sure to choose <strong>Import project from
     58         external model</strong> and select the <strong>Gradle</strong> option.
     59       </p>
     60     </li>
     61   </ol>
     62 
     63 <p class="note">
     64   <strong>Note:</strong> When starting Android Studio, you can also select <strong>Import
     65   Non-Android Studio project</strong> in the Welcome to Android Studio wizard to import a
     66   downloaded sample project.
     67 </p>
     68 
     69 
     70 <p class="note">
     71   <strong>Note:</strong> At this time, the downloadable projects are designed for use with Gradle
     72     and Android Studio.
     73 </p>
     74 
     75