Android Tutorial
Android Tutorial
Development Tutorial
Background
Introduction to Android
Overview of Sensors
Programming Tutorial 1: Tracking location with
GPS and Google Maps
Overview of Networking
Programming Tutorial 2: Downloading from the
Internet
Programming Tutorial 3: Sending/Receiving SMS
Messages
Questions/Comments
Resources
Topics
Introduction to Android
A brief guide to the Android Application Development Environment
Software platform from Google and the
Open Handset Alliance
July 2005, Google acquired Android, Inc.
November 2007, Open Handset Alliance
formed to develop open standards for
mobile devices
October 2008, Android available as open
source
December 2008, 14 new members joined
Android project
Background
Built-in Apps ≡ Apps created in SDK
Leverage Linux kernel to interface with
hardware
Open source platform promotes
development from global community
Android Features
Android Architecture
Apps are written in Java
Bundled by Android Asset Packaging Tool
Every App runs its own Linux process
Each process has it’s own Java Virtual
Machine
Each App is assigned a unique Linux user
ID
Apps can share the same user ID to see
each other’s files
Application Fundamentals
Activity
◦ Present a visual user interface for one focused endeavor the user can
undertake
◦ Example: a list of menu items users can choose from
Services
◦ Run in the background for an indefinite period of time
◦ Example: calculate and provide the result to activities that need it
Broadcast Receivers
◦ Receive and react to broadcast announcements
◦ Example: announcements that the time zone has changed
Content Providers
◦ Store and retrieve data and make it accessible to all applications
◦ Example: Android ships with a number of content providers for common
data types (e.g., audio, video, images, personal contact information, etc.)
Intents
◦ Hold the content of a message
◦ Example: convey a request for an activity to present an image to the user
or let the user edit some text
Application Components
http://developer.android.com/sdk/installing.html
Preparing your system and system
requirements
Downloading and Installing the SDK
Installing ADT plug-in for Eclipse
Adding Platforms and Components
Exploring the SDK
Completing tutorials
Troubleshooting
Installation
Developer’s are able to access “goodies”
Hardware capabilities made available
Sensor Class representing a sensor. Use getSensorList(int) to get the list of available Sensors.
SensorManager A class that permits access to the sensors available within the Android platform.
An interface used for receiving notifications from the SensorManager when sensor values have
SensorEventListener changed. An application implements this interface to monitor one or more sensors available in the
hardware.
This class represents a sensor event and holds information such as the sensor type (e.g.,
SensorEvent
accelerometer, orientation, etc.), the time-stamp, accuracy and of course the sensor's data.
A class, used to record media samples, that can be useful for recording audio activity within a
specific location (such as a baby nursery). Audio clippings can also be analyzed for identification
MediaRecorder
purposes in an access-control or security application. For example, it could be helpful to open the
door to your time-share with your voice, rather than having to meet with the realtor to get a key.
This class is used to estimated estimate magnetic field at a given point on Earth, and in
GeomagneticField
particular, to compute the magnetic declination from true north.
A class that permits basic recognition of a person's face as contained in a bitmap. Using this as a
FaceDetector
device lock means no more passwords to remember — biometrics capability on a cell phone.
Hardware-oriented Features
Sensor type (Sensor class)
◦ Orientation, accelerometer, light, magnetic field,
proximity, temperature, etc.
Sampling rate
◦ Fastest, game, normal, user interface.
◦ When an application requests a specific sampling
rate, it is really only a hint, or suggestion, to the
sensor subsystem. There is no guarantee of a
particular rate being available.
Accuracy
◦ High, low, medium, unreliable.
5. Copy the MD5 certificate fingerprint and navigate your web browser to:
http://code.google.com/android/maps-api-signup.html.
6. Follow the instructions on the page to complete the application and obtain the
Google Maps key.
For more information on using Google Maps in Android application development:
http://mobiforge.com/developing/story/using-google-maps-android
SMS Sending
• Step 3 Import Classes and Interfaces
import android.app.Activity;
import android.app.PendingIntent;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.SmsManager;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
SMS Sending
Step 4 Write the SMS class
public class SMS extends Activity {
Button btnSendSMS;
EditText txtPhoneNo;
EditText txtMessage;
btnSendSMS.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
String phoneNo = txtPhoneNo.getText().toString();
Input from the
String message = txtMessage.getText().toString(); user (i.e., the
if (phoneNo.length()>0 && message.length()>0) phone no, text
message and
sendSMS(phoneNo, message);
else
Toast.makeText(getBaseContext(),
"Please enter both phone number and message.", sendSMS is
}
Toast.LENGTH_SHORT).show();
implemented).
});
}
}
SMS Sending
Step 5
◦ To send an SMS message, you use the
SmsManager class. And to instantiate this class
call getDefault() static method.
◦ The sendTextMessage() method sends the SMS
message with a PendingIntent.
◦ The PendingIntent object is used to identify a
target to invoke at a later time.
private void sendSMS(String phoneNumber, String message) {
PendingIntent pi = PendingIntent.getActivity(this, 0,
new Intent(this, SMS.class), 0);
SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage(phoneNumber, null, message, pi, null);
}
SMS Sending
SMS Sending
Step 1
Receiving SMS
Step 2
◦ In the AndroidManifest.xml file add the <receiver> element so
that incoming SMS messages can be intercepted by the
SmsReceiver class.
<receiver android:name=".SmsReceiver">
<intent-filter>
<action android:name=
"android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>
Receiving SMS
Step 3
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.telephony.SmsMessage;
import android.widget.Toast;
Receiving SMS
Step 4 In the SmsReceiver class,
public class SmsReceiver extends BroadcastReceiver { extend the
@Override BroadcastReceiver class
public void onReceive(Context context, Intent intent) { and override the
//---get the SMS message passed in--- onReceive() method. The
Bundle bundle = intent.getExtras(); message is attached to
SmsMessage[] msgs = null; the Intent
String str = "";
if (bundle != null){
//---retrieve the SMS message received---
Object[] pdus = (Object[]) bundle.get("pdus");
msgs = new SmsMessage[pdus.length];
Receiving SMS
Receiving SMS
What is Android?
What are the sensor and networking
capabilities in Android?
How to use location data and Google
maps in Android?
How to access websites?
How to send SMS messages across the
network?
Questions/Comments?
Conclusions
Ableson, Frank. “Tapping into Android’s sensors.” www.ibm.com. January 30, 2010.
http://www.ibm.com/developerworks/opensource/library/os-android-sensor/index.html
Ableson, Frank; Collins, Charlie; Sen, Robi. Unlocking Android, A Developer’s Guide.
Greenwich: Manning Publications Co. 2009.
Android Development Guide. January 30, 2010.
http://developer.android.com/guide/index.html
Lee, Wei-Meng. “Using Google Maps in Android.” mobiforge.com. January 30, 2010.
http://mobiforge.com/developing/story/using-google-maps-android
Lee, Wei-Meng. “You Are Here: Using GPS and Google Maps in Android.” www.devx.com.
January 30, 2010. http://www.devx.com/wireless/Article/39239/1954
Lee, Wei-Meng “SMS Messaging in Android” mobiforge.com. January 30, 2010
http://mobiforge.com/developing/story/sms-messaging-android
Lee, Wei-Meng “Connecting to the Web: I/O Programming in Android” November 5,
2008 Android”http://www.devx.com/wireless/Article/39810
Open Handset Alliance, http://www.openhandsetalliance.com/
Patterson, Don. “Android Development Guide.” getsatisfaction.com. January 30, 2010.
http://getsatisfaction.com/luci/topics/android_development_guide
www.androidcompetencycenter.com. January 30, 2010.
http://www.androidcompetencycenter.com/2009/06/accessing-device-sensors
Xianhua Shu; Zhenjun Du; Rong Chen, "Research on Mobile Location Service Design Based
on Android," Wireless Communications, Networking and Mobile Computing, 2009. WiCom
'09. 5th International Conference on , vol., no., pp.1-4, 24-26 Sept. 2009
http://ieeexplore.ieee.org/stamp/stamp.jsp?arnumber=5302615&isnumber=5300799
Resources