This repo is among the largest collections of Android code samples anywhere; it contains around a hundred and fifty compilable source code examples from the O’Reilly Android Cookbook, a great source of tutorial material for the Android Developer. Not all recipes in the book or online have code accompanying them; this repo features code that was either linked by the contributor, or in some cases, re-constructed as a New Project by the editor for your convenience.
Further note that not all programs used in the book/online appear here; some of the examples in the book/online are only program fragments taken from other programs that can’t be included. And of course some code is drawn from existing projects that are hosted elsewhere.
Each directory contains one project, and (if it’s used in the book) has a name that is cited at the end of the corresponding Recipe, under the "Source Code Download" section.
Some older started-in-Eclipse projects also have configuration files to allow them to be opened in Android Studio. During the runup to the second edition of the book, AndMore appeared to be a viable project to maintain Android Eclipse development. However, it has become clear that AndMore has not attracted enough developer talent to remain viable. Accordingly, the newest projects here are Android-Studio-Only. And Issue #1 calls for moving the existing mass of projects to Studio-only format. For reference, a "canonical" project would look something like this:
README.txt app/ ├── app.iml ├── build/ ├── build.gradle ├── libs ├── proguard-rules.pro └── src ├── androidTest │ └── java │ └── com │ └── darwinsys │ └── circleviewgroup │ └── ExampleInstrumentedTest.java ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ └── androidcookbook │ │ └── some_project_name │ │ └── MainActivity.java │ └── res │ ├── drawable │ ├── layout │ │ └── activity_main.xml │ ├── mipmap-hdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ ├── mipmap-* │ └── values │ ├── colors.xml │ ├── strings.xml │ └── styles.xml └── test └── java └── com └── darwinsys └── circleviewgroup └── ExampleUnitTest.java build.gradle gradlew, gradlew.bat local.properties settings.gradle
The table List of Projects lists each project, its author, and a short summary.
*Note that, since Gradle and the Gradle Android Plugin need to be updated just about every time your run Android Studio, there is no attempt made to keep things up-to-date here; just let Studio do its upgrade thing for you and all will be well. They promise. Except for really old projects, where you’d have to upgrade 6 or 8 times. For these, copying newer build.gradle files from ../AndroidTemplate might be a better bet. Or see https://darwinsys.com/blog/2022-07-26-modernize-android/.
JpsTrack and the ToDo applications have graduated to their own github projects, under https://github.com/IanDarwin.
DuellingIDEs has been removed since the duel is over. Just use Android Studio.
The following list is generated (periodically) from the project folders. In the Builds With column, E for Eclipse, M for Maven, S for Android Studio, G for Gradle. The Author names have recently been added; if I have missed or mis-attributed any, please let me know and I will happily correct them. You (and I) know who you are.
Project | Author | Function | Notes |
---|---|---|---|
Ian Darwin |
A re-usable About dialog. |
- |
|
Ian Darwin |
Info about device and screen |
- |
|
Ian Darwin |
Simple ActionBar demo(s) |
- |
|
Ian Darwin |
Add a contact |
Shows ContactsContract, content provider |
|
Ian Darwin |
Using AdMob with interstitial (inter-Activity) ads. |
- |
|
Ian Darwin |
Ashwini’s Google Analytics for Android Demo, slightly updated. |
- |
|
Rachee Singh |
Graphing |
- |
|
Wagied Davids |
RSS Reader |
Works under Maven; Eclipse fails w/ Maven Configuration Problem |
|
Ian Darwin |
Installs another app |
Downloading, package management |
|
Ian Darwin |
Shows App Shortcuts, which appear with long-press on app’s launcher icon. |
- |
|
Ian Darwin |
Compilable example of the Application Singleton pattern recipe. |
- |
|
Ian Darwin |
Demo of AsyncTask (which is deprecated in API 30 but still widely used) |
- |
|
Ian Darwin |
Contact picker with autocomplete |
- |
|
Ian Darwin |
App can update itself |
see AppDownloader |
|
Ian Darwin |
Use Android Backup scheme. |
- |
|
Ian Darwin |
Using BlueTooth to connect |
- |
|
Ian Darwin |
Bluetooth Connection |
- |
|
Ian Darwin |
Use the now-defunct Browser Bookmarks content provider |
- |
|
Ian Darwin |
Add appointment to Calendar |
Calendar via Content Provider |
|
Ian Darwin |
Pretend a call happened, for testing |
- |
|
Johan Pelgrim |
Intercept an incoming phone call. |
- |
|
Johan Pelgrim |
Intercept outgoing phone calls. |
Compiles and runs, but doesn’t intercept the call. |
|
Ian Darwin |
CameraIntent - get the camera to take a picture, using androidx API |
- |
|
Ian Darwin |
Demonstation of Card widget. |
- |
|
Ian Darwin |
GUI demo |
name says it |
|
Ian Darwin |
Attempt at a custom layout manager. |
- |
|
Ian Darwin |
List of bookmarks from Bookmarks Content Provider |
Browser ContentProvider |
|
Ian Darwin |
List of ContentProviders |
- |
|
Ashwini Shahapurkar |
Implement a ContentProvider |
- |
|
Ian Darwin |
Test it |
- |
|
Ian Darwin |
Simple Cordova (nee PhoneGap) cross-platform (web-based) toolkit demo. |
- |
|
Wagied Davids |
Time-based activity |
- |
|
Ian Darwin |
Application Widgets have a live display on the home page, like the standard Clock program. |
- |
|
Ian Darwin |
How to load data properly using CursorLoader |
- |
|
Ian Darwin |
Menu |
- |
|
Ian Darwin |
Submenu, created programmatically |
- |
|
Rachee Singh |
Toast |
- |
|
Ian Darwin |
Create a database from an SQLite .db file in 'assets'. |
- |
|
Ian Darwin |
Fake up a Cursor from a list of files |
- |
|
Ian Darwin |
Example of various DateFormat usages (the Android one, not java.text nor java.time). |
- |
|
Ian Darwin |
A pedagogic project that can be used to show off Smali for short functions. |
- |
|
Ian Darwin |
Dialogs |
- |
|
Ian Darwin |
A simple Drag-and-drop example. |
- |
|
Ian Darwin |
Demo of "Dreams" (4.x screensaver) |
- |
|
Wagied Davids |
Send contents of EditText via email |
- |
|
Marco Dinacci |
Attach file to email |
- |
|
Wagied Davids |
Java + JavaScript Epoch Calendar |
- |
|
Daniel Fowler |
5 Ways to Wire an Event Listener. |
- |
|
N/R. Pending check. |
Access FB API |
- |
|
Wagied Davids |
Face locator API in photos |
- |
|
Ian Darwin |
Demo of FileProvider. |
- |
|
Ian Darwin |
Internal and external files. |
- |
|
Ian Darwin |
Find Me X |
IllegalArgumentException: Incomplete location object, missing timestamp or accuracy, Progress:334 |
|
Ian Darwin |
Demo of 'fab' Floating Abstract Button |
- |
|
Ian Darwin |
Flutter is a new SDK for cross-platform development |
- |
|
Ian Darwin |
Using a custom font |
You need to provide the font file! Example uses Iceberg font… |
|
Ian Darwin |
Simple Fragment and List-Detail Fragments in one project |
- |
|
Ian Darwin |
Simple Photo Gallery example. |
Deprecated |
|
Ian Darwin |
Google Cloud Messaging - receiver |
- |
|
Ian Darwin |
Google Cloud Messaging - sender |
- |
|
Ian Darwin |
A program that shows the Storage Facility to prompt for all files. |
- |
|
Ian Darwin |
Haptic Feedback recipe. |
- |
|
Ian Darwin |
HelloWorld |
SDK |
|
Ian Darwin |
HelloWorld |
Eclipse ADT |
|
Ian Darwin |
HelloWorld of EspressoTesting |
- |
|
Ian Darwin |
Hello World with Gradle but NOT Studio. |
- |
|
Ian Darwin |
HelloWorld using Maven with android-maven-plugin. |
- |
|
Ian Darwin |
HelloWorld of StudioTesting |
- |
|
Adrián Santalla |
ADT Testing - subject |
- |
|
Ian Darwin |
ADT Testing - Tests |
- |
|
Ian Darwin |
A Home Application |
Shows running a program |
|
Ian Darwin |
List View with Icon |
- |
|
Ian Darwin |
ImageButtons! |
- |
|
Ian Darwin |
Intents |
- |
|
Ian Darwin |
IPC - Inter-Process Communication, simplified demo (2 versions, alas). |
- |
|
Rupesh Chavan |
IPC - Inter-Process Communication, simplified demo (2 versions, alas). |
- |
|
Ian Darwin |
Getting data from Java to JavaScript and back. |
- |
|
Ian Darwin |
Demos of java.time date/time API |
Actually JSR-310 API; almost same but different package |
|
Ian Darwin |
Simple example of JSON parsing using built-in JSONObject. |
- |
|
Ian Darwin |
Kotlin version of Volley demo |
- |
|
Ian Darwin |
Layout Border Demo Project Source for Android |
- |
|
Marco Dinacci |
ListView |
- |
|
Ian Darwin |
ListView |
- |
|
Rachee Singh |
ListView with empty list: don’t show blank screen! |
- |
|
Ian Darwin |
ListView with section headers |
- |
|
Ian Darwin |
Local Broadcast Receiver |
- |
|
Ian Darwin |
This is the Google API Maps V2 Demo. |
- |
|
Ian Darwin |
Adding a Google Maps V2 MapActivity to a project |
You must ask for permission from Google (get and provide your own Google API key). |
|
Ian Darwin |
Search the Play Store |
- |
|
Ian Darwin |
MaterialDesign demos |
- |
|
Ian Darwin |
Play media |
- |
|
Ian Darwin |
Media Player demo from Marco Dinacci, thanks. |
- |
|
Marco Dinacci |
Simple sound recorder |
- |
|
Ian Darwin |
Menu Action Handling |
- |
|
Ian Darwin |
Demo the Message API for threading. |
- |
|
Ian Darwin |
Try to invoke native code from JavaScript. |
- |
|
Ian Darwin |
Native Development Kit |
C Code |
|
Ian Darwin |
Notifications |
- |
|
Ian Darwin |
UI for picking numbers |
- |
|
Ian Darwin |
Demo of OAuth2 to Google Tasks. |
- |
|
Marco Dinacci |
OpenGL graphics |
- |
|
Wagied Davids |
Rotation |
- |
|
Rachee Singh |
Basic OSM map app demo. |
Builds with Maven, not with Eclipse. Maybe m2e aar support, isn’t, yet. |
|
Ian Darwin |
OSM Map with a map marker overlay |
Compiles, runs, doesn’t load map tiles; needs upgrading to osmdroid-android 5.5 |
|
Ian Darwin |
OSM Map with touch event handling. |
Builds with Maven, not with Eclipse. Maybe m2e aar support, isn’t, yet. |
|
Ian Darwin |
Create and share a PDF |
- |
|
Ian Darwin |
Shows asking for permissions at runtime, i.e,. "the new way" |
- |
|
Shraddha Shravagi |
HTML5 app using phonegap/cordova |
- |
|
Ian Darwin |
Pinch-and-zoom graphics demo |
- |
|
Ian Darwin |
Preferences |
- |
|
Ian Darwin |
Demo of a pop-up indefinite progress dialog. |
- |
|
Ian Darwin |
Using a graphing library |
- |
|
Ian Darwin |
Show use of 5-star RatingBar as used in rankings, surveys, &c. |
- |
|
Ian Darwin |
How to reboot, and why you can’t |
- |
|
Ian Darwin |
= RecipeList - use an AsyncTask to download data over the 'net via HTTP. |
- |
|
Ian Darwin |
Demo of RecyclerView, the faster ListView. |
- |
|
Ian Darwin |
This folder is created automatically by Eclipse and can be ignored. |
- |
|
Wagied Davids |
Using a graphing library |
- |
|
Ian Darwin |
Demo of Room, the official Android ORM. |
- |
|
Ian Darwin |
A simpe runtime log facility |
- |
|
Ian Darwin |
Scan barcode using ZXing app via Intent |
- |
|
Ian Darwin |
Trivial example of one Activity (screen) starting another. |
- |
|
Colin Wilcox |
Sends an SMS |
- |
|
Thomas Manthey |
Use Accellerometer to detect if the user has shaken the device. |
- |
|
Rachee Singh |
Code for r2051, Checking Whether a Device Is Facing Up or Down |
- |
|
Ian Darwin |
Demo a couple of kinds of Service. |
- |
|
Ian Darwin |
ICS "Share" action |
- |
|
Ian Darwin |
Run a Unix/Linux command via Runtime.exec, capture the output. |
- |
|
Ian Darwin |
User account on device |
- |
|
Ian Darwin |
Calendar |
- |
|
Ian Darwin |
Trivial Dialer - launches Dialer app via Intent |
- |
|
Wagied Davids |
Common code for flixel-gdx-based gaming demo. |
Game starts, can move left-right only, no scenery. Fails on Intel phone/emulator |
|
Wagied Davids |
Start of a pool/billiards game using AndEngine. |
- |
|
Saketkumar Srivastav |
Simple Torchlight/Flashlight example. |
(Most devices now have a built-in control for this) |
|
Wagied Davids |
The main code is from the "Sliding Drawer - Top Down" recipe |
- |
|
Ian Darwin |
Receive an incoming SMS. |
- |
|
Ian Darwin |
Snackbar (bottom message text) demo |
- |
|
Ian Darwin |
XML SOAP Web Service |
- |
|
Jonathan Fuerth |
Change the Enter key to "Next" on one-line text fields. |
- |
|
Ian Darwin |
Sound Recorder |
- |
|
Ian Darwin |
Text To Speech (TTS) |
- |
|
Ian Darwin |
Speech Recognizer. |
- |
|
Ian Darwin |
Drop-down Spinner Demos |
- |
|
Marco Dinacci |
OpenGL Spinning Cube, from Marco Dinacci |
- |
|
Rachee Singh |
Splash screen |
- |
|
Ian Darwin |
SQLite demos |
- |
|
Ian Darwin |
Use Existing Drawables |
- |
|
Ian Darwin |
StaticFileRead - read a file from the application |
- |
|
Daniel Fowler |
Demos for "Nuances of Strings.xml" recipe. |
- |
|
Ian Darwin |
TabHost Demo: Demo of the TabHost widget, in a Dialog. |
- |
|
Ian Darwin |
Tabbable and swipeable layout |
- |
|
Ian Darwin |
Telephone call recorder (in progress!) |
- |
|
Pratik Rupwal |
Displays phone info |
- |
|
Sunit Katkar |
Full app: compute and show restaurant bill with tip |
- |
|
Ian Darwin |
Find device’s unique ID |
- |
|
Rachee Singh |
Make the device vibrate |
- |
|
Ian Darwin |
Swipe among views |
- |
|
Ian Darwin |
Demo of Volley networking library |
- |
|
Wagied Davids |
Apple-style Wheel Picker Demo |
- |
|
Ian Darwin |
Graphical window background |
- |