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);
}