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>For more information about importing samples, see
     39 <a href="{@docRoot}tools/studio/index.html#git-samples">Easy access to Android code samples on
     40 GitHub</a>.</p>
     41 
     42 <h2>Download Samples</h2>
     43 
     44 <p>Although importing samples from Android Studio is the recommended method, you can also use the
     45 categories on the left to browse the available samples and learn how to build different components
     46 for your applications.</p>
     47 
     48 <p>If you want to download a complete project, just click on any source file in the project and
     49   click the <strong>Download</strong> link in the upper right of the source page.</p>
     50 
     51 <p>To import a downloaded project:<p>
     52 
     53   <ol>
     54     <li>Unpack the downloaded project package.</li>
     55     <li>In <a href="{@docRoot}sdk/installing/studio.html">Android Studio</a>, chose
     56     <strong>File &gt; Import Project</strong> and select the root folder of the unpacked project.
     57       <p>Android Studio may ask you to choose the type of project you are importing.
     58         If this is the case, make sure to choose <strong>Import project from
     59         external model</strong> and select the <strong>Gradle</strong> option.
     60       </p>
     61     </li>
     62   </ol>
     63 
     64 <p class="note">
     65   <strong>Note:</strong> When starting Android Studio, you can also select <strong>Import
     66   Non-Android Studio project</strong> in the Welcome to Android Studio wizard to import a
     67   downloaded sample project.
     68 </p>
     69 
     70 
     71 <p class="note">
     72   <strong>Note:</strong> At this time, the downloadable projects are designed for use with Gradle
     73     and Android Studio. 
     74 </p>
     75 
     76