Tek Eye Logo

Tek Eye

Android SDK Samples as Examples for Guidance

If you are new to programming on Android devices it can sometimes be difficult to figure out how to achieve a particular task, especially when the documentation is sketchy or does not provide any example code. Looking at existing working code is always a good way to learn.

Stuck Using Android?

Stuck on Using an Android API? Try a SDK Example App

The Android Software Development Kit (SDK) comes with free example App projects. These sample programs can be picked apart to see how they function.

Update: Google no longer provide the SDK samples as a download. Now samples are imported from the online Google github repository. They can be accessed from the Android Studio start-up screen Welcome to Android Studio. (To access the start-up screen close any open project in Studio). From the start-up screen select Import an Android code sample.

Android Sample Projects

The remainder of the article is kept for historical purposes only.

The Old Way Get the Sample Projects

Android SDK Samples

To download the SDK example Apps use the SDK Manager, installed with Android Studio or the standalone Android SDK, see Keeping the Android SDK Updated.

In the android-sdk folder there is a samples folder. The samples folder has a sub-folder for every API level sample Apps that have been downloaded. The samples are grouped by functionality using further sub-folders.

Android Example Apps

Android SDK Legacy Samples

Prior to Android Studio being Googles preferred Integrated Development Environment (IDE) the Eclipse IDE was used. The Android SDK samples could be imported to Eclispe and run. With the release of Android API level 18 (Android version 4.3) all the previous API samples were placed into the legacy sub-folder. New samples were added, organised into further sub-folders, that support the Gradle build system provided with Studio.

Here, in the following table, is a list of the Android legacy sample Apps. The API column indicates which API level SDK the example App was first seen. The sample is usually in subsequent API platforms but not always. (For example the NFCDemo first appears in API 10 then again in 14 and 15 before disappearing from 16 and 17. Fortunately you can load example Apps from early APIs to run on later APIs.)

List of Android Legacy Sample Projects With Source Code

Name Folder Name Summary API
Accelerometer Play AccelerometerPlay Use of the Accelerometer 10+
Action Bar Compatibility ActionBarCompat Using the Android 3.0 Action Bar functionality in pre-Android and post-Android 3.0 Apps 14+
Android Beam Demo AndroidBeamDemo Transmission between two devices via NFC 14+
API Demos ApiDemos Demo showing general Android interfaces and topics 7+
App Navigation AppNavigation Different Navigation Scenarios 15+
Backup and Restore BackupRestore Using the BackupAgent API 8+
Basic Open GL to SurfaceView BasicGLSurfaceView Simple Open GL example 10+
Bluetooth Chat BluetoothChat Transmission between devices using Bluetooth 7+
Bluetooth Health Device Profile BluetoothHDP Connect to a Bluetooth enabled health device 14+
Contact Manager ContactManager Interaction with the systems contacts provider 7+
Cross Compatibility CrossCompatibility Testing SDK build version for version specific functionality 10+
Cube Live Wallpaper CubeLiveWallpaper Example of building an packaging a live wallpaper 7+
Gesture Builder GestureBuilder Detect and store gestures 7+
Media Effects HelloEffects Add media effects to images and videos 16+
Home Home A home screen replacement 7+
Honeycomb Gallery HoneycombGallery An image gallery built with fragments 11+
JetBoy JetBoy A game that uses JetPlayer to demonstrate SONiVOX JET 7+
Key Chain Demo KeyChainDemo Security certificates and keys management demo 16+
Lunar Lander LunarLander An example game 7+
Multiple Resolutions MultiResolution How to use the resource qualifiers to support multiple resolutions 7+
NFC Demo NFCDemo Reading Near Field Communication tags 10+
Note Pad NotePad An example App making notes 7+
Random Music Player RandomMusicPlayer How to play music on a device 13+
RenderScript RenderScript An example using RenderScript 11+
SampleSyncAdapter SampleSyncAdapter A example of syncing with web based data 7+
Searchable Dictionary SearchableDictionary Using the Android search framework and Quick Search Box 7+
SIP Demo SipDemo Session Initiation Protocol example (Internet telephony) 10+
Skeleton App SkeletonApp A barebones App 7+
Snake Snake An example game 7+
Soft Keyboard SoftKeyboard A keyboard implementation 7+
Spell Checker SpellChecker Spell checker exmaple 14+
Spinner Spinner The App for the testing tutorial see also SpinnerTest 8+
SpinnerTest SpinnerTest A test program for the Spinner testing App tutorial 8+
TicTacToeLib TicTacToeLib Example of using a library 8+
TicTacToeMain TicTacToeMain App that uses the library project 8+
Toy VPN Client ToyVpn Example of a custom Virtual Private Network 14+
Text to Speech Engine TtsEngine Using the Test to Speech engine 14+
USB USB Use of the USB APIs 12+
Voicemail Provider VoicemailProviderDemo Use of the voicemail content provider APIs 14+
Base Recognition Service VoiceRecognitionService Skeleton App for a new Recognition Service 8+
Weather Widget WeatherListWidget A basic weather Widget example 11+
Widget Preview WidgetPreview Grab a screenshot of a Widget 11+
Wi-Fi Direct Demo WiFiDirectDemo Demonstrating use of the Wi-Fi Direct APIs 14+
Wi-Fi Direct Service Discovery WiFiDirectServiceDiscovery Demonstrating use of Wi-Fi P2P Services 17+
Wiktionary Wiktionary Home screen Widget example 7+
Wicktionary (Simplified) WiktionarySimple A simple Widget example 7+
XML Adapters XmlAdapters Using XMLAdapters to bind data to Views 11+

Using the Legacy Samples Code

The legacy samples have no project files to allow for a project import. However, the legacy samples can be added to a new project. Create a new application named after the legacy sample. Select Add No Activity when asked to select an Activity to add to the new project. Copy and merge the contents of the res folder for the legacy sample into the main/res folder for the new project. Likewise copy the Java class files from the src folders for the legacy sample to the correct main/java folders in the new App. Studio automatically shows the new files in the new project because it reflects the directory structure on the system. Correct any references and namespaces in the Java files due to the new project structure. The copied files may be read only and Studio will display a message when the files are edited. Merge the contents of the legacy sample's AndroidManifest.xml file with the new projects manifest file. Ensuring the activity (with intent-filters) and uses-permissions sections are correctly copied. Once the legacy sample code is building with no error the App will be ready to run.

Android SDK Gradle Example Apps

The following table lists the Android example Apps provided by the various Android SDKs for the new Gradle build system in Studio.

List of Android SDK Gradle Build Example Apps

App Summary API
admin folder Apps that demonstrate enterprise device management. 21+
AppRestrictionEnforcer App restrictions demo for managed devices. 21+
AppRestrictionSchema UI restrictions demo for managed devices. 21+
BasicManagedProfile Managed Profile API demo. 21+
DeviceOwner Using device owner features. 22+
androidtv folder Demo Apps for Android TV. 21+
leanback Example Android TV UI App 21+
sample-inputs Live TV App demo. 22+
visual-game-controller Game controller demo. 21+
background folder Background tasks demos. 19+
JobScheduler Background tasks scheduling. 21+
RepeatingAlarmSample Alarm activated intent example. 19+
connectivity folder External connectivity demos. 18+
BasicNetworkDemo Network connectivity checking. 18
BasicNetworking Network connectivity checking. 19+
BasicSyncAdapter Background data download. 18+
bluetooth Bluetooth chat. 20+
BluetoothLeGatt Transfer data via Bluetooth. 19+
CardEmulation NFC card emulation. 19+
CardReader NFC card reader. 19+
NetworkConnect Fetching HTML on background thread. 18+
content folder Device content access. 18+
AppRestrictions Restrict profile demo. 19+
AutoBackupForApps Automatic backups settings demo. 23
BasicContactables Contacts search. 18+
documentsUI Directory selection demo. 22+
StorageClient Document providers access demo. 19+
StorageProvider Document provider demo. 19+
webview Accessing restricted feature from a WebView. 22+
input folder Demos detecting touch actions. 18+
BasicGestureDetect Gesture detection. 18+
BasicMultitouch Multi-touch points demo. 18+
media folder Media demos. 18+
BasicMediaDecoder Video decode and rendering. 19+
BasicMediaRouter Route media to secondary display. 18+
Camera2Basic Access the camera. 21+
Camera2Raw Camera access for frame data. 21+
Camera2Video Record video. 21+
HdrViewfinder High dynamic range demo. 21+
MediaEffects Using the media effects API. 20+
MediaRecorder Using the MediaRecorder API for the camera. 19+
MediaRouter Custom media router provider. 19+
ScreenCapture Media Projection API for device screen capture. 22+
nfc folder NFC Provisioning demo. 22+
NfcProvisioning Device provisioning via NFC. 22+
notification folder Notifications demos. 21+
ActiveNotifications How many notifications is the App showing? 23
BasicNotifications Show a notification. 21-22
CustomNotifications Notifications with custom content views. 21-22
LNotifictions New notification types. 21-22
MessagingService Notification messages and Android Auto. 21-22
renderscript folder RenderScript usage. 19+
BasicRenderScript Basic image manipulation. 19+
RenderScriptIntrinsic Using RenderScript built in functions (Intrinsics). 19+
security folder Using device security access features. 18+
BasicAndroidKeyStore Create and store encryption keys. 18+
ConfirmCredential Using device protection in an App. 23
FingerprintDialog Fingerprint authentication. 23
sensors folder Sensor demo. 19+
BatchStepSensor Using the step sensor. 19+
system folder App permissions and usage demos. 22+
AppUsageStatistics Collecting App usage stats. 22+
RuntimePermissions Checking and collecting run-time permissions. 23
RuntimePermissionsBasic Basic use of run-time permissions. 23
testing folder Testing demo. 18+
ActivityInstrumentation Using testing instrumentation. 18+
ui folder User Interface demos. 18+
ActionBarCompat-Basic Action bar demo. 18+
ActionBarCompat-ListPopupMenu Pop-up menu. 18+
ActionBarCompat-ShareActionProvider ViewPager with ShareActionProvider. 18+
ActionBarCompat-Styled ActionBar styling. 18+
AdapterTransition Overlay layout transitions. 19-20
activityscenetransition Scene transitions. 21+
activitytasks/DocumentCentricApps The new FLAG_ACTIVITY_NEW_DOCUMENT intent action. 21+
activitytasks/DocumentCentricRelenquishIdentity Change an activities base activity. 21+
AdvancedImmersiveMode Full screen demo. 19+
BasicAccessibility Accessibility demo. 18+
BasicImmersiveMode Basic full screen demo. 19+
BasicNotifications Show a notification. 18+
BasicTransition Transitions demo. 19+
BorderlessButtons Halo borderless button styling. 18+
CustomChoiceList Custom checkable layouts. 18+
CustomNotifications Notifications with custom content views. 19+
CustomTransition Custom transitions. 19+
DisplayingBitmaps Efficient bitmap loading and display. 19+
DoneBar ActionBar Done button. 18+
DrawableTinting Filters for Drawables. 21+
graphics Rendering PDF. 21+
HorizontalPaging Tabs swiping. 18+
ImmersiveMode Swipe status bar and navigation bar in and out. 19+
Interpolator Motion animation. 21+
notifications Notification types. 23
SlidingTabsBasic SlidingTabLayout with a ViewPager. 19+
SlidingTabsColors Customised SlidingTabLayout with a ViewPager. 19+
SwipeRefreshLayoutBasic Swipe to refresh demo. 19+
SwipeRefreshListFragment ListView swipe to refresh. 19+
SwipeRefreshMultipleViews Swipe to refresh child view. 19+
TextLinkify Clickable links in a TextView. 19+
TextSwitcher Text animations. 18+
views/CardView CarView demo. 21+
views/Clipping Clipping a View. 21+
views/Elevation/ElevationBasic Changing View elevation demo. 21+
views/Elevation/ElevationDrag View elevation drag an drop demo. 21+
views/FloatingActionButton Checkable floating action button. 21+
views/NavigationDrawer DrawerLayout widget. 21+
views/RecyclerView Recycle views for datasets. 21+
views/RevealEffect Circular reveal effect. 21+
wearable folder Android wearables demos. 20+
AgendaData Calendar sync. 20+
DataLayer Use of DataEvents. 20+
DelayedConfirmation Wearable callback to device demo. 20+
ElizaChat Wearable notifications demo. 20+
FindMyPhone Mislaid device warning demo. 20+
EmbeddedApp Embedding a wearable App in a device App. 20-21
Flashlight A flashlight demo for wearable. 20+
Geofencing Geofencing with a wearable. 20+
GridViewPager GridViewPager on a wearable. 20+
JumpingJack Using the gravity sensor. 20+
Notifications Wearable notifications. 20+
Quiz Questions on a wearable from a device. 20+
RecipeAssistant Step-by-step instructions. 20+
SkeletonWearableApp Basic wearable App. 20+
SpeedTracker Calculate wearable device speed. 20+
SynchronizedNotifications Wearable and device synchronised notifications. 20+
Timer Countdown timer. 20+
WatchFace Creating watch faces. 21+
WatchViewStub Layouts for circular and square watches. 20+
XYZTouristAttractions Wearable and device interaction demo. 22+

Running the Android SDK Example Apps

The Android Studio welcome screen has two import options (to return to the Welcome to Android Studio screen close the currently opened project):

  • Import project (Eclipse ADT, Gradle, etc.) - Import a local project.
  • Import an Android code sample - Import a GitHub hosted Android sample.

Welcome to Android Studio

Use the local project import to open an SDK sample App. Select the sample App to open in Studio.

Android Studio Import Project

The App is opened from the directory it is located. (To use the sample in a different location copy it to the new directory before importing it.) When Studio imports the project the Gradle status is shown on the bottom status bar.

Studio Gradle Status

When Gradle has finished the project can be run on an Android device, virtual or real.

Many of the GitHub hosted samples are the same as those available from the downloaded samples. However, there are projects not in the downloaded samples and the downloaded samples have projects not available on GitHub. Browse both sets of samples to become familiar with what is available.

Input GitHub Hosted Sample

Choose the location for the GitHub imported sample.

Choosing the Location for a Sample

Loading the Android samples on to your development machine and running a sample project is straightforward. In summary use the SDK Manager program to install the samples. Then in Studio use the import option to load the sample. After a short time the project will be ready to run and the Android sample source code can be browsed to see how it works.

Demos Sample Running

See Also

The Android SDK provides a few samples for the Support Library. The article Support Library Samples in The Android SDK provides some information. The article will be updated for Studio in due course.

If after looking at the documentation, trying a sample app, and searching the web you still need some help with an Android code problem then ask someone a question. Try Stack Overflow using the Tag android.

Don't forget to browse the posts on this site. Articles covering programming will be added regularly, including Android.

For more example Android Apps try the following:

If migrating from Eclipse see the https://developer.android.com/studio/intro/migrate

Archived Comments

André Herculano on December 4, 2013 at 1:57 pm said: Really useful list! There’s a lot of android samples but no description about each of them.

Comments

Lucian on November 10, 2022 at 15:59 said: This page is very nice. I am learning programming in Android.

Author:  Published:  Updated:  

ShareSubmit to TwitterSubmit to FacebookSubmit to LinkedInSubmit to redditPrint Page

Do you have a question or comment about this article?

(Alternatively, use the email address at the bottom of the web page.)

 This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

markdown CMS Small Logo Icon ↓markdown↓ CMS is fast and simple. Build websites quickly and publish easily. For beginner to expert.


Articles on:

Android Programming and Android Practice Projects, HTML, VPS, Computing, IT, Computer History, ↓markdown↓ CMS, C# Programming, Using Windows for Programming


Free Android Projects and Samples:

Android Examples, Android List Examples, Android UI Examples



Tek Eye Published Projects