SlideShare a Scribd company logo
TIB Academy
5/3,Varathur Road, Kundalahalli Gate,
Bangalore- 560066
+91-9513332301 / 02 www.traininginbangalore.com
 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
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
 April 30, 2009: Official 1.5 Cupcake release
 September 15, 2009: 1.6 SDK Donut release
 October 26, 2009: 2.0 SDK Éclair release
 Updates to the Éclair release:
 2.0.1 on December 3, 2009
 2.1 on January 12, 2010
Android tutorial for beginners-traininginbangalore.com
 Built-in Apps ≡ Apps created in SDK
 Leverage Linux kernel to interface with
hardware
 Open source platform promotes development
from global community
 Reuse and replacement of components
 Dalvik virtual machine
 Integrated browser
 Optimized graphics
 SQLite
 Media support
 GSM Telephony
 Bluetooth, EDGE, 3G, and WiFi
 Camera, GPS, compass, and accelerometer
 Rich development environment
Android tutorial for beginners-traininginbangalore.com
 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
 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
 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
The Android Sensor Platform and how to use it
 Developer’s are able to access “goodies”
 Hardware capabilities made available
Feature Description
Camera
A class that enables your application to interact with the camera to snap a photo, acquire images for a preview
screen, and modify parameters used to govern how the camera operates.
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.
SensorEventListener
An interface used for receiving notifications from the SensorManager when sensor values have changed. An
application implements this interface to monitor one or more sensors available in the hardware.
SensorEvent
This class represents a sensor event and holds information such as the sensor type (e.g., accelerometer,
orientation, etc.), the time-stamp, accuracy and of course the sensor's data.
MediaRecorder
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 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.
GeomagneticField
This class is used to estimated estimate magnetic field at a given point on Earth, and in particular, to compute
the magnetic declination from true north.
FaceDetector
A class that permits basic recognition of a person's face as contained in a bitmap. Using this as a device lock
means no more passwords to remember — biometrics capability on a cell phone.
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.
Simulating an Android application that accesses positioning
sensors
 Must have Eclipse IDE installed
 Must have Android SDK installed
 Must have knowledge of Java
 Must have the external Google Maps library
installed in your SDK environment. The Maps
library is included with the Google APIs add-
on, which you can install using the Android
SDK and AVD Manager.
 A Google Maps API key is required to integrate Google Maps into your
Android application.
 To apply for a key:
1. Locate the SDK debug certificate in the default folder of "C:Documents and
Settings<username>Local SettingsApplication DataAndroid". The filename of the
debug keystore is debug.keystore.
2. Copy the debug.keystore file to a folder named C:Android.
3. Open the command window and navigate to C:Program
FilesJava<JDK_version_number>bin to locate the Keytool.exe.
4. Execute the following to extract the MD5 fingerprint:
keytool.exe -list -alias androiddebugkey -keystore
"C:Androiddebug.keystore" -storepass android -keypass android
1. Copy the MD5 certificate fingerprint and navigate your web browser to:
http://code.google.com/android/maps-api-signup.html.
2. 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
 Defines the system image and device settings used
by the Emulator
 To create an AVD in Eclipse:
1. Select Window > Android SDK and AVD Manager.
The Android SDK and AVD Manager displays.
1. Make sure the entry for Virtual Devices is selected and
click New.
The Create new AVD window displays.
1. Enter a Name for the AVD.
2. Select Google APIs (API level 3) as the Target.
3. Click Create AVD.
4. Close the Android SDK and AVD Manager.
To create the project in Eclipse:
1. Select File > New > Project.
2. Select Android Project in the Android folder and
click Next.
3. Enter GPSSimulator as the Project Name.
4. Select Google APIs (Platform 1.5) as the Build Target.
5. Enter GPSSimulator as the Application name.
6. Enter com.android.gpssimulator as the Package
name.
7. Enter GPSSimulator as the Activity name.
8. Click Finish.
Android tutorial for beginners-traininginbangalore.com
Add permissions for GPS
To modify the AndroidManifest.xml file:
1. Click on the res folder in the GPSSimulator project.
2. Double-click AndroidManifest.xml to display the
GPSSimulator Manifest.
3. Enter the following lines before the application tag.
<uses-permission
android:name=“android.permission.ACCESS_FINE_LOCATION” />
1. Save the changes to the file.
public class GPSSimulator extends Activity
{
private LocationManager lm;
private LocationListener locationListener;
// Called when the activity is first created.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// use the LocationManager class to obtain GPS locations
lm = (LocationManager)
getSystemService(Context.LOCATION_SERVICE);
locationListener = new MyLocationListener();
lm.requestLocationUpdates(
LocationManager.GPS_PROVIDER, 0, 0, locationListener);
}
}
private class MyLocationListener implements LocationListener {
@Override
public void onLocationChanged(Location loc) {
if (loc != null) {
Toast.makeText(getBaseContext(),
"Location changed : Lat: " + loc.getLatitude() +
" Lng: " + loc.getLongitude(),
Toast.LENGTH_SHORT).show();
}
}
@Override
public void onProviderDisabled(String provider) {
// TODO Auto-generated method stub
}
@Override
public void onProviderEnabled(String provider) {
// TODO Auto-generated method stub
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
// TODO Auto-generated method stub
}
}
 To test in Eclipse:
1. Switch to DDMS view.
2. Find the Location Controls in the Emulator Control
tab.
3. Click the GPX tab and click Load GPX.
4. Locate and select the GPX file.
5. Click Play to begin sending coordinates to the
Emulator.
 Update the Manifest with two lines.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.android.GPSSimulator">
<uses-permission
android:name="android.permission.INTERNET" />
<uses-permission
android:name="android.permission.ACCESS_FINE_LOCATION" />
<application android:icon="@drawable/icon"
android:label="@string/app_name">
<uses-library android:name="com.google.android.maps" />
<activity android:name=".GPS" android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<com.google.android.maps.MapView
android:id="@+id/mapview1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:enabled="true"
android:clickable="true"
android:apiKey=“Your API Key Here" />
</LinearLayout>
public class GPSSimulator extends MapActivity {
private LocationManager lm;
private LocationListener locationListener;
private MapView mapView;
private MapController mc;
// Called when the activity is first created.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// use the LocationManager class to obtain GPS locations
lm = (LocationManager)
getSystemService(Context.LOCATION_SERVICE);
locationListener = new MyLocationListener();
lm.requestLocationUpdates(
LocationManager.GPS_PROVIDER, 0, 0, locationListener);
mapView = (MapView) findViewById(R.id.mapview1);
mc = mapView.getController();
}
@Override
protected boolean isRouteDisplayed() {
return false;
}
private class MyLocationListener implements LocationListener {
@Override
public void onLocationChanged(Location loc) {
if (loc != null) {
Toast.makeText(getBaseContext(),
"Location changed : Lat: " + loc.getLatitude() +
" Lng: " + loc.getLongitude(),
Toast.LENGTH_SHORT).show();
GeoPoint p = new GeoPoint(
(int) (loc.getLatitude() * 1E6),
(int) (loc.getLongitude() * 1E6));
mc.animateTo(p);
mc.setZoom(16);
mapView.invalidate();
}
}
@Override
public void onProviderDisabled(String provider) {
}
@Override
public void onProviderEnabled(String provider) {
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
}
}
}
Android tutorial for beginners-traininginbangalore.com
 The Internet, is based on a
layered architecture called the
TCP/IP stack.
 Link Layer
◦ Protocols: ARP and RARP
 Internet Layer
◦ Protocols: IP, ping, etc.
 Transport
◦ Protocols: TCP and UDP
 Application Layer
◦ Protocols: HTTP, FTP, DNS, etc.
 A server machine is identified on the Internet by some IP
address
 Daemons are the processes running in the background
which are listening all the time for connection requests
from clients on a particular port number.
 Once a connection request comes into the server on a
given port, the corresponding daemon can choose to
accept it, and if so, a connection is established.
 Then the application layer protocol is typically used for
the client to get or send data to the server.

More Related Content

What's hot (20)

PDF
Android development Training Programme Day 2
DHIRAJ PRAVIN
 
PDF
Android App Development Intro at ESC SV 2012
Opersys inc.
 
PPT
9780134433646 annuzzi ch02 (1)
Peter Mburu
 
PDF
Android development training programme Day 1
DHIRAJ PRAVIN
 
PDF
Os eclipse-androidwidget-pdf
weerabahu
 
PPSX
ANDROID
Ranjan Som
 
PPTX
Android Application Development
Ramesh Prasad
 
PPTX
All about android
Inimitable Harish
 
PPT
Industrial Training in Android Application
Arcadian Learning
 
PPTX
Android Overview
Raju Kadam
 
PPT
PPT Companion to Android
Dharani Kumar Madduri
 
ODP
Introduction to Android App Development
Todd Burgess
 
PPT
MTJ Taking Mobile Java Developers to the Next Level
gustavoeliano
 
PPTX
Android Development Basics
Prajakta Dharmpurikar
 
PPTX
Introduction to Android (in-short) - Itvedant, Thane | Mumbai | Navi Mumbai
Itvedant
 
PDF
STUDY OF AN APPLICATION DEVELOPMENT ENVIRONMENT BASED ON UNITY GAME ENGINE
AIRCC Publishing Corporation
 
PPT
1 introduction of android
akila_mano
 
PPTX
Android Apps Development Basic
Monir Zzaman
 
PPT
Android
Natasha Ramírez
 
PDF
Android Development
vishalkrv
 
Android development Training Programme Day 2
DHIRAJ PRAVIN
 
Android App Development Intro at ESC SV 2012
Opersys inc.
 
9780134433646 annuzzi ch02 (1)
Peter Mburu
 
Android development training programme Day 1
DHIRAJ PRAVIN
 
Os eclipse-androidwidget-pdf
weerabahu
 
ANDROID
Ranjan Som
 
Android Application Development
Ramesh Prasad
 
All about android
Inimitable Harish
 
Industrial Training in Android Application
Arcadian Learning
 
Android Overview
Raju Kadam
 
PPT Companion to Android
Dharani Kumar Madduri
 
Introduction to Android App Development
Todd Burgess
 
MTJ Taking Mobile Java Developers to the Next Level
gustavoeliano
 
Android Development Basics
Prajakta Dharmpurikar
 
Introduction to Android (in-short) - Itvedant, Thane | Mumbai | Navi Mumbai
Itvedant
 
STUDY OF AN APPLICATION DEVELOPMENT ENVIRONMENT BASED ON UNITY GAME ENGINE
AIRCC Publishing Corporation
 
1 introduction of android
akila_mano
 
Android Apps Development Basic
Monir Zzaman
 
Android Development
vishalkrv
 

Similar to Android tutorial for beginners-traininginbangalore.com (20)

PPT
Android - Android Application Configuration
Vibrant Technologies & Computers
 
PPT
Android
Jesus_Aguirre
 
PDF
Android tutorial
master760
 
PPT
Android tutorial
Techacademy Software
 
PPT
Android tutorial
Ed Zel
 
PPT
Android tutorial
katayoon_bz
 
PPT
Android tutorial
Keshav Chauhan
 
PPT
Android-Tutorial.ppt
siddharthsingh496426
 
PPT
Android tutorial
Avinash Nandakumar
 
PDF
Android tutorial ppt
Rehna Renu
 
PDF
Android tutorial
Vaiga Nandhakumar
 
PDF
Android tutorial
Jagannath Das
 
PDF
Android tutorial
Danish_k
 
PDF
Android tutorial
Alberto Jr Gaudicos
 
PDF
An Introduction To Android
natdefreitas
 
PDF
Build Your First Android App Session #1
Troy Miles
 
PPTX
Everything About Android - Itvedant, Thane | Mumbai | Navi Mumbai
Itvedant
 
ODP
Java Meetup - 12-03-15 - Android Development Workshop
Kasun Dananjaya Delgolla
 
PPTX
Introduction to Android (before 2015)
Chien-Ming Chou
 
PDF
Day1 before getting_started
Ahsanul Karim
 
Android - Android Application Configuration
Vibrant Technologies & Computers
 
Android
Jesus_Aguirre
 
Android tutorial
master760
 
Android tutorial
Techacademy Software
 
Android tutorial
Ed Zel
 
Android tutorial
katayoon_bz
 
Android tutorial
Keshav Chauhan
 
Android-Tutorial.ppt
siddharthsingh496426
 
Android tutorial
Avinash Nandakumar
 
Android tutorial ppt
Rehna Renu
 
Android tutorial
Vaiga Nandhakumar
 
Android tutorial
Jagannath Das
 
Android tutorial
Danish_k
 
Android tutorial
Alberto Jr Gaudicos
 
An Introduction To Android
natdefreitas
 
Build Your First Android App Session #1
Troy Miles
 
Everything About Android - Itvedant, Thane | Mumbai | Navi Mumbai
Itvedant
 
Java Meetup - 12-03-15 - Android Development Workshop
Kasun Dananjaya Delgolla
 
Introduction to Android (before 2015)
Chien-Ming Chou
 
Day1 before getting_started
Ahsanul Karim
 
Ad

More from TIB Academy (18)

PDF
AWS Training Institute in Bangalore | Best AWS Course In Bangalore
TIB Academy
 
PDF
MySQL training in Bangalore | Best MySQL Course in Bangalore
TIB Academy
 
PDF
CCNA Training in Bangalore | Best Networking course in Bangalore
TIB Academy
 
PDF
Core Java Training in Bangalore | Best Core Java Class in Bangalore
TIB Academy
 
PDF
Advance Java Training in Bangalore | Best Java Training Institute
TIB Academy
 
PPTX
Best Hadoop Training in Bangalore - TIB Academy
TIB Academy
 
PPTX
Selenium training for beginners
TIB Academy
 
PPTX
Python Training
TIB Academy
 
PPTX
TIB Academy provides best Oracal DBA classes in Bangalore
TIB Academy
 
PPTX
java tutorial for beginner - Free Download
TIB Academy
 
PPTX
Aws tutorial for beginners- tibacademy.in
TIB Academy
 
PPT
C C++ tutorial for beginners- tibacademy.in
TIB Academy
 
PPTX
Java tutorial for beginners-tibacademy.in
TIB Academy
 
PPTX
Hadoop tutorial for beginners-tibacademy.in
TIB Academy
 
PPT
SoapUI Training in Bangalore
TIB Academy
 
PPT
R programming
TIB Academy
 
PPT
Spring-training-in-bangalore
TIB Academy
 
PPTX
Salesforce Certification
TIB Academy
 
AWS Training Institute in Bangalore | Best AWS Course In Bangalore
TIB Academy
 
MySQL training in Bangalore | Best MySQL Course in Bangalore
TIB Academy
 
CCNA Training in Bangalore | Best Networking course in Bangalore
TIB Academy
 
Core Java Training in Bangalore | Best Core Java Class in Bangalore
TIB Academy
 
Advance Java Training in Bangalore | Best Java Training Institute
TIB Academy
 
Best Hadoop Training in Bangalore - TIB Academy
TIB Academy
 
Selenium training for beginners
TIB Academy
 
Python Training
TIB Academy
 
TIB Academy provides best Oracal DBA classes in Bangalore
TIB Academy
 
java tutorial for beginner - Free Download
TIB Academy
 
Aws tutorial for beginners- tibacademy.in
TIB Academy
 
C C++ tutorial for beginners- tibacademy.in
TIB Academy
 
Java tutorial for beginners-tibacademy.in
TIB Academy
 
Hadoop tutorial for beginners-tibacademy.in
TIB Academy
 
SoapUI Training in Bangalore
TIB Academy
 
R programming
TIB Academy
 
Spring-training-in-bangalore
TIB Academy
 
Salesforce Certification
TIB Academy
 
Ad

Recently uploaded (20)

PPTX
Post Dated Cheque(PDC) Management in Odoo 18
Celine George
 
PPTX
GRADE-3-PPT-EVE-2025-ENG-Q1-LESSON-1.pptx
EveOdrapngimapNarido
 
PPTX
PPT-Q1-WEEK-3-SCIENCE-ERevised Matatag Grade 3.pptx
reijhongidayawan02
 
PPTX
How to Handle Salesperson Commision in Odoo 18 Sales
Celine George
 
PPTX
Growth and development and milestones, factors
BHUVANESHWARI BADIGER
 
PPTX
PPT-Q1-WK-3-ENGLISH Revised Matatag Grade 3.pptx
reijhongidayawan02
 
PPTX
PATIENT ASSIGNMENTS AND NURSING CARE RESPONSIBILITIES.pptx
PRADEEP ABOTHU
 
PPTX
CATEGORIES OF NURSING PERSONNEL: HOSPITAL & COLLEGE
PRADEEP ABOTHU
 
PPTX
Identifying elements in the story. Arrange the events in the story
geraldineamahido2
 
PPTX
How to Create a PDF Report in Odoo 18 - Odoo Slides
Celine George
 
PDF
Aprendendo Arquitetura Framework Salesforce - Dia 03
Mauricio Alexandre Silva
 
PPTX
How to Set Up Tags in Odoo 18 - Odoo Slides
Celine George
 
PPTX
care of patient with elimination needs.pptx
Rekhanjali Gupta
 
PDF
Stokey: A Jewish Village by Rachel Kolsky
History of Stoke Newington
 
PPT
Talk on Critical Theory, Part One, Philosophy of Social Sciences
Soraj Hongladarom
 
PDF
Women's Health: Essential Tips for Every Stage.pdf
Iftikhar Ahmed
 
PPTX
How to Create Odoo JS Dialog_Popup in Odoo 18
Celine George
 
PDF
Exploring the Different Types of Experimental Research
Thelma Villaflores
 
PDF
Chapter-V-DED-Entrepreneurship: Institutions Facilitating Entrepreneurship
Dayanand Huded
 
PPTX
How to Convert an Opportunity into a Quotation in Odoo 18 CRM
Celine George
 
Post Dated Cheque(PDC) Management in Odoo 18
Celine George
 
GRADE-3-PPT-EVE-2025-ENG-Q1-LESSON-1.pptx
EveOdrapngimapNarido
 
PPT-Q1-WEEK-3-SCIENCE-ERevised Matatag Grade 3.pptx
reijhongidayawan02
 
How to Handle Salesperson Commision in Odoo 18 Sales
Celine George
 
Growth and development and milestones, factors
BHUVANESHWARI BADIGER
 
PPT-Q1-WK-3-ENGLISH Revised Matatag Grade 3.pptx
reijhongidayawan02
 
PATIENT ASSIGNMENTS AND NURSING CARE RESPONSIBILITIES.pptx
PRADEEP ABOTHU
 
CATEGORIES OF NURSING PERSONNEL: HOSPITAL & COLLEGE
PRADEEP ABOTHU
 
Identifying elements in the story. Arrange the events in the story
geraldineamahido2
 
How to Create a PDF Report in Odoo 18 - Odoo Slides
Celine George
 
Aprendendo Arquitetura Framework Salesforce - Dia 03
Mauricio Alexandre Silva
 
How to Set Up Tags in Odoo 18 - Odoo Slides
Celine George
 
care of patient with elimination needs.pptx
Rekhanjali Gupta
 
Stokey: A Jewish Village by Rachel Kolsky
History of Stoke Newington
 
Talk on Critical Theory, Part One, Philosophy of Social Sciences
Soraj Hongladarom
 
Women's Health: Essential Tips for Every Stage.pdf
Iftikhar Ahmed
 
How to Create Odoo JS Dialog_Popup in Odoo 18
Celine George
 
Exploring the Different Types of Experimental Research
Thelma Villaflores
 
Chapter-V-DED-Entrepreneurship: Institutions Facilitating Entrepreneurship
Dayanand Huded
 
How to Convert an Opportunity into a Quotation in Odoo 18 CRM
Celine George
 

Android tutorial for beginners-traininginbangalore.com

  • 1. TIB Academy 5/3,Varathur Road, Kundalahalli Gate, Bangalore- 560066 +91-9513332301 / 02 www.traininginbangalore.com
  • 2.  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
  • 3. A brief guide to the Android Application Development Environment
  • 4. 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
  • 5.  April 30, 2009: Official 1.5 Cupcake release  September 15, 2009: 1.6 SDK Donut release  October 26, 2009: 2.0 SDK Éclair release  Updates to the Éclair release:  2.0.1 on December 3, 2009  2.1 on January 12, 2010
  • 7.  Built-in Apps ≡ Apps created in SDK  Leverage Linux kernel to interface with hardware  Open source platform promotes development from global community
  • 8.  Reuse and replacement of components  Dalvik virtual machine  Integrated browser  Optimized graphics  SQLite  Media support  GSM Telephony  Bluetooth, EDGE, 3G, and WiFi  Camera, GPS, compass, and accelerometer  Rich development environment
  • 10.  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
  • 11.  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
  • 12.  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
  • 13. The Android Sensor Platform and how to use it
  • 14.  Developer’s are able to access “goodies”  Hardware capabilities made available
  • 15. Feature Description Camera A class that enables your application to interact with the camera to snap a photo, acquire images for a preview screen, and modify parameters used to govern how the camera operates. 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. SensorEventListener An interface used for receiving notifications from the SensorManager when sensor values have changed. An application implements this interface to monitor one or more sensors available in the hardware. SensorEvent This class represents a sensor event and holds information such as the sensor type (e.g., accelerometer, orientation, etc.), the time-stamp, accuracy and of course the sensor's data. MediaRecorder 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 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. GeomagneticField This class is used to estimated estimate magnetic field at a given point on Earth, and in particular, to compute the magnetic declination from true north. FaceDetector A class that permits basic recognition of a person's face as contained in a bitmap. Using this as a device lock means no more passwords to remember — biometrics capability on a cell phone.
  • 16. 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.
  • 17. Simulating an Android application that accesses positioning sensors
  • 18.  Must have Eclipse IDE installed  Must have Android SDK installed  Must have knowledge of Java  Must have the external Google Maps library installed in your SDK environment. The Maps library is included with the Google APIs add- on, which you can install using the Android SDK and AVD Manager.
  • 19.  A Google Maps API key is required to integrate Google Maps into your Android application.  To apply for a key: 1. Locate the SDK debug certificate in the default folder of "C:Documents and Settings<username>Local SettingsApplication DataAndroid". The filename of the debug keystore is debug.keystore. 2. Copy the debug.keystore file to a folder named C:Android. 3. Open the command window and navigate to C:Program FilesJava<JDK_version_number>bin to locate the Keytool.exe. 4. Execute the following to extract the MD5 fingerprint: keytool.exe -list -alias androiddebugkey -keystore "C:Androiddebug.keystore" -storepass android -keypass android 1. Copy the MD5 certificate fingerprint and navigate your web browser to: http://code.google.com/android/maps-api-signup.html. 2. 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
  • 20.  Defines the system image and device settings used by the Emulator  To create an AVD in Eclipse: 1. Select Window > Android SDK and AVD Manager. The Android SDK and AVD Manager displays. 1. Make sure the entry for Virtual Devices is selected and click New. The Create new AVD window displays. 1. Enter a Name for the AVD. 2. Select Google APIs (API level 3) as the Target. 3. Click Create AVD. 4. Close the Android SDK and AVD Manager.
  • 21. To create the project in Eclipse: 1. Select File > New > Project. 2. Select Android Project in the Android folder and click Next. 3. Enter GPSSimulator as the Project Name. 4. Select Google APIs (Platform 1.5) as the Build Target. 5. Enter GPSSimulator as the Application name. 6. Enter com.android.gpssimulator as the Package name. 7. Enter GPSSimulator as the Activity name. 8. Click Finish.
  • 23. Add permissions for GPS To modify the AndroidManifest.xml file: 1. Click on the res folder in the GPSSimulator project. 2. Double-click AndroidManifest.xml to display the GPSSimulator Manifest. 3. Enter the following lines before the application tag. <uses-permission android:name=“android.permission.ACCESS_FINE_LOCATION” /> 1. Save the changes to the file.
  • 24. public class GPSSimulator extends Activity { private LocationManager lm; private LocationListener locationListener; // Called when the activity is first created. @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); // use the LocationManager class to obtain GPS locations lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE); locationListener = new MyLocationListener(); lm.requestLocationUpdates( LocationManager.GPS_PROVIDER, 0, 0, locationListener); } }
  • 25. private class MyLocationListener implements LocationListener { @Override public void onLocationChanged(Location loc) { if (loc != null) { Toast.makeText(getBaseContext(), "Location changed : Lat: " + loc.getLatitude() + " Lng: " + loc.getLongitude(), Toast.LENGTH_SHORT).show(); } } @Override public void onProviderDisabled(String provider) { // TODO Auto-generated method stub } @Override public void onProviderEnabled(String provider) { // TODO Auto-generated method stub } @Override public void onStatusChanged(String provider, int status, Bundle extras) { // TODO Auto-generated method stub } }
  • 26.  To test in Eclipse: 1. Switch to DDMS view. 2. Find the Location Controls in the Emulator Control tab. 3. Click the GPX tab and click Load GPX. 4. Locate and select the GPX file. 5. Click Play to begin sending coordinates to the Emulator.
  • 27.  Update the Manifest with two lines. <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.android.GPSSimulator"> <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <application android:icon="@drawable/icon" android:label="@string/app_name"> <uses-library android:name="com.google.android.maps" /> <activity android:name=".GPS" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest>
  • 28. <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <com.google.android.maps.MapView android:id="@+id/mapview1" android:layout_width="fill_parent" android:layout_height="fill_parent" android:enabled="true" android:clickable="true" android:apiKey=“Your API Key Here" /> </LinearLayout>
  • 29. public class GPSSimulator extends MapActivity { private LocationManager lm; private LocationListener locationListener; private MapView mapView; private MapController mc; // Called when the activity is first created. @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); // use the LocationManager class to obtain GPS locations lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE); locationListener = new MyLocationListener(); lm.requestLocationUpdates( LocationManager.GPS_PROVIDER, 0, 0, locationListener); mapView = (MapView) findViewById(R.id.mapview1); mc = mapView.getController(); } @Override protected boolean isRouteDisplayed() { return false; } private class MyLocationListener implements LocationListener { @Override public void onLocationChanged(Location loc) { if (loc != null) { Toast.makeText(getBaseContext(), "Location changed : Lat: " + loc.getLatitude() + " Lng: " + loc.getLongitude(), Toast.LENGTH_SHORT).show(); GeoPoint p = new GeoPoint( (int) (loc.getLatitude() * 1E6), (int) (loc.getLongitude() * 1E6)); mc.animateTo(p); mc.setZoom(16); mapView.invalidate(); } } @Override public void onProviderDisabled(String provider) { } @Override public void onProviderEnabled(String provider) { } @Override public void onStatusChanged(String provider, int status, Bundle extras) { } } }
  • 31.  The Internet, is based on a layered architecture called the TCP/IP stack.  Link Layer ◦ Protocols: ARP and RARP  Internet Layer ◦ Protocols: IP, ping, etc.  Transport ◦ Protocols: TCP and UDP  Application Layer ◦ Protocols: HTTP, FTP, DNS, etc.
  • 32.  A server machine is identified on the Internet by some IP address  Daemons are the processes running in the background which are listening all the time for connection requests from clients on a particular port number.  Once a connection request comes into the server on a given port, the corresponding daemon can choose to accept it, and if so, a connection is established.  Then the application layer protocol is typically used for the client to get or send data to the server.

Editor's Notes

  • #5: Android is the software platform from Google and the Open Handset Alliance that some say has the potential to revolutionize the global cell phone market. Android is a software environment built for mobile devices. It is not a hardware platform. While components of the underlying OS are written in C or C++, user applications are built for Android in Java. In July 2005, Google acquired Android, Inc., a small startup company based in Palo Alto, CA. 4 of Android&amp;apos;s co-founders went to work at Google. At Google, the team developed a mobile device platform powered by the Linux kernel which they marketed to handset makers and carriers on the premise of providing a flexible, upgradeable system. On 5 November 2007, the Open Handset Alliance, a consortium of several companies including Texas Instruments, Google, Intel, Motorola, and Sprint Nextel (just to name a few) announced the goal to develop open standards for mobile devices and unveiled their first product, Android, a mobile device platform built on the Linux kernel. Open Handset Alliance is an alliance of approximately 30 organizations committed to bringing a “better” and “open” mobile phone to market. A quote taken from its website says it best: “Android was built from the ground up with the explicit goal to be the first open, complete, and free platform created specifically for mobile devices.” Android has been available as open source since October 2008. Google opened the entire source code under an Apache License. With the Apache License, vendors are free to add proprietary extensions without submitting those back to the open source community. On 9 December 2008, 14 new members joined the Android project including Garmin, Sony Ericsson, Toshiba, and Vodafone Group.
  • #6: Update history Android has seen a number of updates since its original release. These updates to the base Operating System typically fix bugs and add new features. On 30 April 2009, the official 1.5 (Cupcake) update for Android was released. On 15 September 2009, the 1.6 (Donut) SDK was released. On 26 October 2009 the 2.0 (Eclair) SDK was released On 3 December 2009 the 2.0.1 SDK was released. On 12 January 2010 the 2.1 SDK was released.
  • #7: This page provides data about the relative number of active devices running a given version of the Android platform. This can help you understand the landscape of device distribution and decide how to prioritize the development of your application features for the devices currently in the hands of users. Data collected during two weeks ending on 1/4/2010
  • #8: In the Android platform, there is no difference between the built-in applications and applications created with the SDK. This means that powerful applications can be written to tap into the resources available on the device. Android is software only. Leveraging its Linux kernel to interface with the hardware, you can expect Android to run on many different devices from multiple cell phone manufacturers. Android is an open source platform; missing elements can and will be provided by the global developer community. Android’s Linux kernel–based OS does not come with a sophisticated shell environment, but because the platform is open, shells can be written and installed on a device. Likewise, multimedia codecs can be supplied by third-party developers and do not need to rely on Google or anyone else to provide new functionality. That is the power of an open source platform brought to the mobile market. Ableson, Frank; Collins, Charlie; Sen, Robi. Unlocking Android, A Developer’s Guide. Greenwich: Manning Publications Co. 2009.
  • #9: Enables reuse and replacement of components Dalvik virtual machine optimized for mobile devices Integrated browser based on the open source WebKit engine Optimized graphics powered by a custom 2D graphics library; 3D graphics based on the OpenGL ES 1.0 specification (hardware acceleration optional) SQLite for structured data storage Media support for common audio, video, and still image formats (MPEG4, H.264, MP3, AAC, AMR, JPG, PNG, GIF) GSM Telephony (hardware dependent) Bluetooth, EDGE, 3G, and WiFi (hardware dependent) Camera, GPS, compass, and accelerometer (hardware dependent) Rich development environment including a device emulator, tools for debugging, memory and performance profiling, and a plugin for the Eclipse IDE
  • #10: Applications Android will ship with a set of core applications including an email client, SMS program, calendar, maps, browser, contacts, and others. All applications are written using the Java programming language. Application Framework By providing an open development platform, Android offers developers the ability to build extremely rich and innovative applications. Developers are free to take advantage of the device hardware, access location information, run background services, set alarms, add notifications to the status bar, and much, much more. Developers have full access to the same framework APIs used by the core applications. The application architecture is designed to simplify the reuse of components; any application can publish its capabilities and any other application may then make use of those capabilities (subject to security constraints enforced by the framework). This same mechanism allows components to be replaced by the user. Underlying all applications is a set of services and systems, including: A rich and extensible set of Views that can be used to build an application, including lists, grids, text boxes, buttons, and even an embeddable web browser Content Providers that enable applications to access data from other applications (such as Contacts), or to share their own data A Resource Manager, providing access to non-code resources such as localized strings, graphics, and layout files A Notification Manager that enables all applications to display custom alerts in the status bar An Activity Manager that manages the lifecycle of applications and provides a common navigation backstack Libraries Android includes a set of C/C++ libraries used by various components of the Android system. These capabilities are exposed to developers through the Android application framework. Some of the core libraries are listed below: System C library - a BSD-derived implementation of the standard C system library (libc), tuned for embedded Linux-based devices Media Libraries - based on PacketVideo&amp;apos;s OpenCORE; the libraries support playback and recording of many popular audio and video formats, as well as static image files, including MPEG4, H.264, MP3, AAC, AMR, JPG, and PNG Surface Manager - manages access to the display subsystem and seamlessly composites 2D and 3D graphic layers from multiple applications LibWebCore - a modern web browser engine which powers both the Android browser and an embeddable web view SGL - the underlying 2D graphics engine 3D libraries - an implementation based on OpenGL ES 1.0 APIs; the libraries use either hardware 3D acceleration (where available) or the included, highly optimized 3D software rasterizer FreeType - bitmap and vector font rendering SQLite - a powerful and lightweight relational database engine available to all applications Android Runtime Android includes a set of core libraries that provides most of the functionality available in the core libraries of the Java programming language. Every Android application runs in its own process, with its own instance of the Dalvik virtual machine. Dalvik has been written so that a device can run multiple VMs efficiently. The Dalvik VM executes files in the Dalvik Executable (.dex) format which is optimized for minimal memory footprint. The VM is register-based, and runs classes compiled by a Java language compiler that have been transformed into the .dex format by the included &amp;quot;dx&amp;quot; tool. The Dalvik VM relies on the Linux kernel for underlying functionality such as threading and low-level memory management. Linux Kernel Android relies on Linux version 2.6 for core system services such as security, memory management, process management, network stack, and driver model. The kernel also acts as an abstraction layer between the hardware and the rest of the software stack.
  • #11: Android applications are written in the Java programming language. The compiled Java code — along with any data and resource files required by the application — is bundled by the Android Asset Packaging Tool into an Android package, an archive file marked by an .apk suffix. This file is the vehicle for distributing the application and installing it on mobile devices; it&amp;apos;s the file users download to their devices. All the code in a single .apk file is considered to be one application. In many ways, each Android application lives in its own world: By default, every application runs in its own Linux process. Android starts the process when any of the application&amp;apos;s code needs to be executed, and shuts down the process when it&amp;apos;s no longer needed and system resources are required by other applications. Each process has its own Java virtual machine (VM), so application code runs in isolation from the code of all other applications. By default, each application is assigned a unique Linux user ID. Permissions are set so that the application&amp;apos;s files are visible only that user, only to the application itself — although there are ways to export them to other applications as well. It&amp;apos;s possible to arrange for two applications to share the same user ID, in which case they will be able to see each other&amp;apos;s files. To conserve system resources, applications with the same ID can also arrange to run in the same Linux process, sharing the same VM.
  • #12: Application Components A central feature of Android is that one application can make use of elements of other applications (provided those applications permit it). For example, if your application needs to display a scrolling list of images and another application has developed a suitable scroller and made it available to others, you can call upon that scroller to do the work, rather than develop your own. Your application doesn&amp;apos;t incorporate the code of the other application or link to it. Rather, it simply starts up that piece of the other application when the need arises. For this to work, the system must be able to start an application process when any part of it is needed, and instantiate the Java objects for that part. Therefore, unlike applications on most other systems, Android applications don&amp;apos;t have a single entry point for everything in the application (no main() function, for example). Rather, they have essential components that the system can instantiate and run as needed. There are four types of components: Activities An activity presents a visual user interface for one focused endeavor the user can undertake. For example, an activity might present a list of menu items users can choose from or it might display photographs along with their captions. A text messaging application might have one activity that shows a list of contacts to send messages to, a second activity to write the message to the chosen contact, and other activities to review old messages or change settings. Though they work together to form a cohesive user interface, each activity is independent of the others. Each one is implemented as a subclass of the Activity base class. An application might consist of just one activity or, like the text messaging application just mentioned, it may contain several. What the activities are, and how many there are depends, of course, on the application and its design. Typically, one of the activities is marked as the first one that should be presented to the user when the application is launched. Moving from one activity to another is accomplished by having the current activity start the next one. Services A service doesn&amp;apos;t have a visual user interface, but rather runs in the background for an indefinite period of time. For example, a service might play background music as the user attends to other matters, or it might fetch data over the network or calculate something and provide the result to activities that need it. Each service extends the Service base class. A prime example is a media player playing songs from a play list. The player application would probably have one or more activities that allow the user to choose songs and start playing them. Broadcast receivers A broadcast receiver is a component that does nothing but receive and react to broadcast announcements. Many broadcasts originate in system code — for example, announcements that the timezone has changed, that the battery is low, that a picture has been taken, or that the user changed a language preference. Content providers A content provider makes a specific set of the application&amp;apos;s data available to other applications. Android ships with a number of content providers for common data types (audio, video, images, personal contact information, etc.) Intents Activities, services, and broadcast receivers — are activated by asynchronous messages called intents. An intent is an Intent object that holds the content of the message. For activities and services, it names the action being requested and specifies the URI of the data to act on, among other things. For example, it might convey a request for an activity to present an image to the user or let the user edit some text. For broadcast receivers, the Intent object names the action being announced. For example, it might announce to interested parties that the camera button has been pressed.
  • #13: The installation documentation provided by Android for the SDK is excellent. If you navigate to the website shown on the slide, you will find information about… Follow the instructions exactly, and you will creating you first Android app in no time.
  • #15: One refreshing aspect of working with the Android platform is that you can access some of the &amp;quot;goodies&amp;quot; within the device itself. Historically, the inability to access the underlying hardware of a device has been frustrating to mobile developers. Though the Android Java environment still sits between you and the metal, the Android development team brings much of the hardware&amp;apos;s capability to the surface. The platform is open source, so you have the flexibility to roll up your sleeves and write some code to accomplish your tasks.
  • #16: This table describes some of the hardware-oriented features exposed in the Android SDK.
  • #17: The Sensor and Sensor Manager classes contains several constants, which represent different aspects of Android&amp;apos;s sensor system, including:
  • #22: The ADT plugin provides a New Project Wizard that you can use to quickly create a new Android project (or a project from existing code). To create a new project: Select File &amp;gt; New &amp;gt; Project. Select Android &amp;gt; Android Project, and click Next. Select the contents for the project: Enter a Project Name. This will be the name of the folder where your project is created. Under Contents, select Create new project in workspace. Select your project workspace location. Under Target, select an Android target to be used as the project&amp;apos;s Build Target. The Build Target specifies which Android platform you&amp;apos;d like your application built against. Unless you know that you&amp;apos;ll be using new APIs introduced in the latest SDK, you should select a target with the lowest platform version possible, such as Android 1.1. Note: You can change your the Build Target for your project at any time: Right-click the project in the Package Explorer, select Properties, select Android and then check the desired Project Target. Under Properties, fill in all necessary fields. Enter an Application name. This is the human-readable title for your application — the name that will appear on the Android device. Enter a Package name. This is the package namespace (following the same rules as for packages in the Java programming language) where all your source code will reside. Select Create Activity (optional, of course, but common) and enter a name for your main Activity class. Enter a Min SDK Version. This is an integer that indicates the minimum API Level required to properly run your application. Entering this here automatically sets the minSdkVersion attribute in the &amp;lt;uses-sdk&amp;gt; of your Android Manifest file. If you&amp;apos;re unsure of the appropriate API Level to use, copy the API Level listed for the Build Target you selected in the Target tab. Click Finish.
  • #23: Once you complete the New Project Wizard, ADT creates the following folders and files in your new project: src/ Includes your stub Activity Java file. All other Java files for your application go here. &amp;lt;Android Version&amp;gt;/ (e.g., Android 1.1/) Includes the android.jar file that your application will build against. This is determined by the build target that you have chosen in the New Project Wizard. gen/ This contains the Java files generated by ADT, such as your R.java file and interfaces created from AIDL files. A project&amp;apos;s R.java file is an index into all the resources defined in the file. You use this class in your source code as a sort of short-hand way to refer to resources you&amp;apos;ve included in your project. This is particularly powerful with the code-completion features of IDEs like Eclipse because it lets you quickly and interactively locate the specific reference you&amp;apos;re looking for. assets/ This is empty. You can use it to store raw asset files. res/ A folder for your application resources, such as drawable files, layout files, string values, etc. The difference between &amp;quot;resources&amp;quot; and &amp;quot;assets&amp;quot; isn&amp;apos;t much on the surface, but in general, you&amp;apos;ll use resources to store your external content much more often than you&amp;apos;ll use assets. The real difference is that anything placed in the resources directory will be easily accessible from your application from the R class, which is compiled by Android. Whereas, anything placed in the assets directory will maintain its raw file format. So keeping files and data in resources (res/) makes them easily accessible. AndroidManifest.xml The Android Manifest for your project. Every application must have an AndroidManifest.xml file (with precisely that name) in its root directory. The manifest presents essential information about the application to the Android system, information the system must have before it can run any of the application&amp;apos;s code. Among other things, the manifest does the following: It names the Java package for the application. The package name serves as a unique identifier for the application. It describes the components of the application — the activities, services, broadcast receivers, and content providers that the application is composed of. It names the classes that implement each of the components and publishes their capabilities (for example, which Intent messages they can handle). These declarations let the Android system know what the components are and under what conditions they can be launched. It determines which processes will host application components. It declares which permissions the application must have in order to access protected parts of the API and interact with other applications. It also declares the permissions that others are required to have in order to interact with the application&amp;apos;s components. It lists the Instrumentation classes that provide profiling and other information as the application is running. These declarations are present in the manifest only while the application is being developed and tested; they&amp;apos;re removed before the application is published. It declares the minimum level of the Android API that the application requires. It lists the libraries that the application must be linked against. default.properties This file contains project settings, such as the build target. This files is integral to the project, as such, it should be maintained in a Source Revision Control system. It should never be edited manually — to edit project properties, right-click the project folder and select &amp;quot;Properties&amp;quot;.
  • #24: To use GPS functionality in your Android application, you&amp;apos;ll need to add the ACCESS_FINE_LOCATION permission to the AndroidManifest.xml file: Open Listing4 file Open AndroidManifest.xml. Copy line into xml file.
  • #25: Show GPSSimulator.java The first thing you will see when you open the GPSSimulator.java file is that an onCreate() method has already been added. The onCreate() method is called by the system when the service is first created and permits the application to perform initialization-type tasks. Once inside the onCreate() method, the setContentView() method is where we will associate the XML layout file main. Override is an annotation type used to mark methods that override a method declaration in a superclass. Here, after the Activity, complete with necessary views, is started, the lifecycle takes over and the onCreate() method is invoked. This is one of a series of important lifecycle methods the Activity class provides. Every Activity will override onCreate(), where component initialization steps are invoked. Android gives your applications access to the location services supported by the device through the classes in the android.location package. The central component of the location framework is the LocationManager system service, which provides an API to determine location and bearing if the underlying device (if it supports location capabilities). Using the LocationManager class, your application can obtain periodic updates of the device&amp;apos;s geographical locations as well as fire an intent when it enters the proximity of a certain location. Listing1.txt In the GPSSimulator.java file, first obtain a reference to the LocationManager class using the getSystemService() method. To be notified whenever there is a change in location, you need to register for a request for changes in locations using the requestLocationUpdates() method so that your program can be notified periodically. The requestLocationUpdates() method takes in four parameters: provider: The name of the provider with which you register minTime: The minimum time interval for notifications, in milliseconds. minDistance: The minimum distance interval for notifications, in meters. listener: An object whose onLocationChanged() method will be called for each location update.
  • #26: Listing 2 We also need to add the MyLocationListener class. The MyLocationListener class implements the LocationListener abstract class. There are four methods that you need to override in this implementation: onLocationChanged(Location location): This method is called when the location has changed. When a location changes you will display a small dialog on the screen showing the new location information: latitude and longitude. You show this dialog using the Toast class. onProviderDisabled(String provider): This method is called when the provider is disabled by the user. onProviderEnabled(String provider): This method is called when the provider is enabled by the user. onStatusChanged(String provider, int status, Bundle extras): This method is called when the provider status changes. In this example, you&amp;apos;re more interested in what happens when a location changes, so you&amp;apos;ll write some code in the onLocationChanged() method (Listing 2).
  • #27: To test the application, press F11 in Eclipse to debug the application on the Android emulator. While at the time of writing this article, you may not have a real Android device to test, there are a number of ways to test GPS functionality on your Android application. The DDMS tool in the Android plug-in for Eclipse allows you to test GPS functionality very easily. In Eclipse, switch to the DDMS view and locate the Location Controls section in the Emulator Control tab (see Figure 1). There are three separate tabs in the Location Controls section. First, you can manually send in the coordinates by specifying the latitude and longitude. When the GPS data is received on the Android emulator, the application will display the latitude and longitude obtained (see Figure 2). Another way to send in geographical locations is to use a .GPX file. GPX (GPS Exchange Format) is a light-weight XML data format for interchange of GPS data. You can download GPS samples here. Once a .GPX file is downloaded, click the Load GPX… button to load the .GPX file (see Figure 3). You can click the Play button to send a series of coordinates to the Android emulator at regular time intervals. The Android Eclipse plug-in also supports KML (Keyhole Markup Language) files. You can download a sample .KML file here. Like the .GPX file, you can also send a series of coordinates to the Android emulator by clicking on the Play button (see Figure 4).
  • #28: Simply displaying the latitude and longitude when a location has changed is not very interesting. A much more interesting thing to do would be to couple the data together with the Google Maps application. For Google Maps to work, you need to add the ACCESS_FINE_LOCATION permission (which we added earlier) and then use the Google Maps library . We will also need to add a permission to access the Internet. Open listing 3 and add Internet permission above ACCESS_FINE_LOCATION and Google Maps code in application but before activity.
  • #29: In main.xml, replace the &amp;lt;TextView&amp;gt; element with the &amp;lt;MapView&amp;gt; element: Main.xml is where you define a layout for application display. Open Listing 4 and replace TextView code with MapView code before &amp;lt;/LinearLayout&amp;gt;
  • #30: Finally, modify the GPS.java file to incorporate Google Maps (see Listing 5). We need to change the GPSSimulator class to extend MapActivity, which is a special subclass of Activity. We create a new MapView object as well as and MapController object. The key class in the Maps package is com.google.android.maps.MapView, a subclass of ViewGroup. A MapView displays a map with data obtained from the Google Maps service. When the MapView has focus, it will capture keypresses and touch gestures to pan and zoom the map automatically, including handling network requests for additional maps tiles. It also provides all of the UI elements necessary for users to control the map. Your application can also use MapView class methods to control the MapView programmatically and draw a number of Overlay types on top of the map. In general, the MapView class provides a wrapper around the Google Maps API that lets your application manipulate Google Maps data through class methods, and it lets you work with Maps data as you would other types of Views. MapController is a utility class to manage panning and zooming of a map. We call the MapView method getController(), which returns the MapController for this map. The isRouteDisplayed() method is required, so add it inside the class as well. This method is required for some accounting from the Maps service to see if you&amp;apos;re currently displaying any route information. In this case, you&amp;apos;re not, so return false. In the MyLocationListener class we have to add a GeoPoint object as well as support for the Google Maps. A GeoPoint object represents a geographical location. GeoPoint defines the map coordinates and are specified in microdegrees. For this tutorial, we use the getLatitude() and getLongitude() methods to retrieve the coordinates from the input. Then, we do the calculation to convert to microdegrees (degrees * 1e6) and save the result to a point p. We then call the MapController method animateTo() to start animating the map towards the given point p. And, call setZoom() to configure the zoom level of the map. Finally, we call the invalidate() method to remove the old map data if there is new data to load.
  • #31: In the above, when a location changes, the latitude and longitude is sent to the Google Maps application, which then displays the map of the current location.