サンプルコード

Android Developersのサンプルコード

サンプルの一覧

Android Developersのサンプル コードには、以下のようなサンプルが用意されています。

対象 プロジェクト 内容
新機能
New Features
TicTacToeLib An example of an Android library project, a type of project that lets you store and manage shared code and resources in one place, then make them available to your other Android applications.
TicTacToeMain Demonstrates how an application can make use of shared code and resources stored in an Android library project.
USB A set of samples that demonstrate how to use various features of the USB APIs.
アクセシビリティ
Accessibility
Accessibility Service Illustrates an accessibility service that provides custom feedback for the Clock application which comes by default with Android devices
ウィジェット
App Widgets
Weather List Widget A more complex collection-widget example which uses a ContentProvider as its data source.
StackView Widget Demonstrates how to create a simple collection widget containing a StackView.
通信
Communication
Bluetooth Chat An application for two-way text messaging over Bluetooth.
アカウントと同期
Accounts & Sync
BusinessCard An application that demonstrates how to launch the built-in contact picker from within an activity. This sample also uses reflection to ensure that the correct version of the contacts API is used, depending on which API level the application is running under.
Contact Manager An application that demonstrates how to query the system contacts provider using the ContactsContract API, as well as insert contacts into a specific account.
SampleSyncAdapter Demonstrates how an application can communicate with a cloud-based service and synchronize its data with data stored locally in a content provider.

The sample uses two related parts of the Android framework - the account manager and the synchronization manager (through a sync adapter).

データアクセス
Data Access
NFC Demo An application for reading NFC Forum Type 2 Tags using the NFC APIs
Note Pad An application for saving notes. Similar (but not identical) to the Notepad tutorial.
データアクセス、アカウントと同期
Data Access and Accounts & Sync
Backup and Restore Illustrates a few different approaches that an application developer can take when integrating with the Android Backup Manager using the BackupAgent API introduced in Android 2.2.
マルチメディア
Multimedia
Random Music Player Demonstrates how to write a multimedia application that plays music from the device and from URLs. It manages media playback from a service and can play music in the background, respecting audio focus changes.
ゲーム開発とマルチメディア
Game Development and Multimedia
JetBoy A game that demonstrates the SONiVOX JET interactive music technology, with JetPlayer.
Lunar Lander A classic Lunar Lander game.
パフォーマンス、ゲーム開発とOpenGL ES
Performance, Game Development and OpenGL ES
RenderScript A set of samples that demonstrate how to use various features of the RenderScript APIs.
インプットメソッド
Input Methods
Soft Keyboard An example of writing an input method for a software keyboard. (IME)
サンプル
Sample
Home A home screen replacement application.
SIP Demo A demo application highlighting how to make internet-based calls with the SIP API.
テスト
Testing
Spinner A simple application that serves as an application under test for the SpinnerTest example.
SpinnerTest The test application for the Activity Testing tutorial. It tests the Spinner example application.
レイアウト/ビュー
Layouts/Views
XML Adapters Binding data to views using XML Adapters examples.
レイアウト/ビューとユーザーインターフェイス
Layouts/Views and User Interface
API Demos A variety of small applications that demonstrate an extensive collection of framework topics.
API 4+ Support Demos A variety of small applications that demonstrate the use of the helper classes in the Android API 4+ Support Library.

(classes which work down to API level 4 or version 1.6 of the platform)

API 13+ Support Demos A variety of small applications that demonstrate the use of the helper classes in the Android API 13+ Support Library.

(classes which work down to API level 13 or version 3.2 of the platform)

Snake An implementation of the classic game "Snake."
ユーザーインターフェイス
User Interface
Honeycomb Gallery An image gallery application using APIs that are new in Android 3.0 (a.k.a. Honeycomb).
Cube Live Wallpaper An application that demonstrates how to create a live wallpaper and bundle it in an application that users can install on their devices.
ユーザーインターフェイスとウィジェット
User Interface and App Widgets
Wiktionary An example of creating interactive widgets for display on the Android home screen.
Wiktionary (Simplified) A simple Android home screen widgets example.
ユーザーインターフェイスと検索
User Interface and Search
Searchable Dictionary v2 A sample application that demonstrates Android's search framework, including how to provide search suggestions for Quick Search Box.
ユーザーインターフェイス、ベストプラクティスとレイアウト/ビュー
User Interface, Best Practices and Layouts/Views
Multiple Resolutions A sample application that shows how to use resource directory qualifiers to provide different resources for different screen configurations.
  Accelerometer Play An example of using the accelerometer to integrate the device's acceleration to a position using the Verlet method. This is illustrated with a very simple particle system comprised of a few iron balls freely moving on an inclined wooden table. The inclination of the virtual table is controlled by the device's accelerometer.

サンプルからのプロジェクト作成

メニューの【File → New → Project】からプロジェクトを作成するときに、[Android Sample Project]を選択することで、Android SDKに含まれるサンプルからプロジェクトを作成できます。

まずBuild Targetで、対象とするAndroidのバージョンを指定します。

次に作成するサンプルを選択します。なお、ここに表示される一覧は、Android SDKのsamplesディレクトリにあるものです。

アプリケーションのソースコード

アプリケーションのapkファイルを逆コンパイルすることでも、ソースコードを得られます。apkファイル自体はZIPで圧縮されているだけのため、まずはそれを展開します。

apkファイルの取得

インストール済みのアプリケーションのapkファイルは、ES File Explorerなどで取得できます。

Androidの情報サイトから、まとめて検索