Image by Aaronage via Flickr
Android is developing applications (software) for Android (mobile) devices.
- Is often referred to as the
Open Handset Alliance
- It includes an operating system, middleware and key applications
- The mobile platform is available, for free, as the
Android Open Source Project
The Android Web site is a good place to start.
Latest Version: Android 2.3
The Android Dev Guide provides a practical introduction to developing applications for Android.
Using Android
System Requirements
Windows XP (32-bit) or Vista (32- or 64-bit)
Mac OS X 10.4.8 or later (x86 only)
Linux (tested on Linux Ubuntu Dapper Drake)
Note: users should download Eclipse and Android SDK (1.6)
- Begin here by Installing the Android SDK
- Those using Eclipse, make sure to install the Android Development Tools (ADT) Plugin
Using Android SDK
- It provides the tools and
APIs needed to begin developing applications.
Using Eclipse
- to edit files and verify that they compile
- used for error checking
- to check directories in search for Java files
Users can highlight and execute a piece of source code by pressing CTRL + SHIFT + D
Users can highlight or select text by pressing ALT + SHIFT + UP ARROW (or DOWN ARROW)
Programming
Android applications are written in the
Java programming language, so learning a bit of Java is necessary.
Also, Android supports XML syntax. It's used for designing application screens.
Need help getting started? There's a helpful forum (blog) that users can learn Android Basic Programming. The site: Android Competency Center. It contains Android tutorials and tips.
For users wanting to build graphical user interfaces for the Android cell phone platform, there's DroidDraw.
Android uses the aapt tool into an Android package, an archive file marked by an .apk suffix.
Using the Android Asset Packaging Tool
./aapt (used by Linux and Mac
OS)
aapt.exe (used by Windows)
- Is included in the tools directory of the SDK
- It allows you to view, create, and update Zip-compatible archives (zip, jar, apk)
Building the code
Note: To build the files, run make from within your working directory.
$ cd ~/mydroid
$ make
Note: If users are missing the "run-java-tool," try setting the ANDROID_JAVA_HOME
env var to $JAVA_HOME
$ export ANDROID_JAVA_HOME=$JAVA_HOME
To
Create an AVD (Android Virtual Devices)
android create avd --target 2 --name my_avd
To Select, Add, Delete, and Modify Data - use the content provider URI (CONTENT_URI)
The CONTENT_URI consist of three parts:
The string “content://”
The segment representing the kind of data to retrieve
The specific item of the specified content provider
Importing (examples):
import android.app.AlertDialog.Builder;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.preference.ListPreference;
import android.preference.Preference;
import android.util.AttributeSet;
To Ask for a User's Name:
androidid=”@+id/nameMessage”
Examples of how to define the activity entry in the AndroidManifest.xml:
android:name=”DialogActivity”
android:label=”@string/activity_dialog”
android:theme=”@android:style/Theme.Dialog”>
…
</activity>
To Create a Dialog:
MyDialog dialog = new MyDialog(context); dialog.show();
Using AlertDialog:
AlertDialog dialog = new AlertDialog.Builder(context).create();
dialog.setMessage(”Do you play golf?”); dialog.setButton(”Yes”, myOnClickListener); dialog.setButton2(”No”, myOnClickListener);
dialog.show();
To Add a Record:
private void insertRecords(
String name, String phoneNo) {
ContentValues values = new ContentValues();
values.put(People.NAME, name);
values.put(Contacts.Phones.TYPE, People.Phones.TYPE_MOBILE);
values.put(People.NUMBER, phoneNo);
}
To Display a Record:
private void displayRecords() {
String columns[] = new String[] { People.NAME, People.NUMBER };
String name = null;
String phoneNo = null;
name = cur.getString(cur.getColumnIndex(People.NAME));
phoneNo = cur.getString(cur.getColumnIndex(People.NUMBER));
}
To Modify a Record:
private void updateRecord(int recNo, String name) {
ContentValues values = new ContentValues();
values.put(People.NAME, name);
}
To Delete a Record:
private void deleteRecords() {
Uri uri = People.CONTENT_URI;
getContentResolver().delete(uri, null, null);
}