SlideShare a Scribd company logo
Android APIs: Phone, Camera,
SMS, GPS, Email
Using Permissions
●

●

●

A basic android application has no permission
associated with it by default.
To make use of the protected features of the
device we declare the <uses-permissions> in
our manifest file.
Permissions are granted by the users when
the application is installed, not while it's
running.
Using Permissions
●

Attributes:
–

android:name
●
●

The name of the permission.
android.permission.CAMERA, etc.

For more: http://bit.ly/19g9vw0
android:maxSdkVersion
●

–

●

●

The highest API level at which the permission should be
granted to your app.
Optional to declare.
Accessing in-built features
●

We always use Intent for this purpose.

●

We have separate ids for these features:
–
–

●

Intent.ACTION_VIEW
Intent.ACTION_SEND

Use of other methods, like:
–

intent.setType()

–

intent.setData()

are also seen.
Phone Call
●

Permission:
<uses-permission android:name=
“android.permission.CALL_PHONE”/>

●

Code:
Intent i = new Intent(Intent.ACTION_CALL);
i.setData(Uri.parse(“tel:980XXXXXXX”));
startActivity(i);
Phone Call
●

If you just want to direct the user to his/her
dialer:
Intent i = new Intent(Intent.ACTION_DIAL);
startActivity(i);

●

No permissions required here.
SMS
●

Code:
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse("smsto:980XXXXXXX"));
startActivity(i);

●

No permissions here.
SMS
●

What if I want to send a message to a user from my
application ??
–

Use SmsManager.
●

–
●

Manages SMS operations such as sending data, text SMS
messages.

Get this object by calling the static method getDefault().

Permission:
<uses-permission android:name=
“android.permission.SEND_SMS”/>
SMS
●

private void sendSMS(String phoneNumber, String message) {
String SENT = "SMS_SENT";
String DELIVERED = "SMS_DELIVERED";

Message and to which
toSend.putExtra("number", phoneNumber); number is it to be sent
Intent toSend = new Intent(SENT);

PendingIntent sentPI = PendingIntent.getBroadcast(this, 0,
toSend, 0);
PendingIntent deliveredPI = PendingIntent.getBroadcast(this, 0,
new Intent(DELIVERED), 0);
SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage(phoneNumber, null, message, sentPI,
deliveredPI);
}

Actual work is done
SMS
●

What is PendingIntent ?
–

Because sending SMS is not our app's function,
the Intent call is forwarded to a foreign
application (to our default messaging app).

–

Using pending intents we specify an action to
take in the future using the same permissions as
your application.
sendTextMessage()
●

The parameters to provide are:
–

First parameter: Destination number/address.

–

Second parameter: Source number/address.

–

Third parameter: The message to be sent

–

Forth parameter: Pending intent/sent intent.

–

Fifth parameter: Pending intent/delivery intent
(was the message delivered?)
Email
●

Permission:
<uses-permission=
“android.permission.INTERNET”/>

●

Coding:
Intent i = new Intent(Intent.ACTION_SEND);
i.setType("text/plain");
startActivity(i);
Email
●

Sending the user straight to G-Mail:
Intent i = new Intent(Intent.ACTION_SENDTO);
i.setType("text/html");
i.setData(Uri.parse("mailto:xxx@abc.com"));
startActivity(i);

●

Adding preset subject and message:
i.putExtra(Intent.EXTRA_SUBJECT, “abc”);
i.putExtra(Intent.EXTRA_TEXT, “abc”);
Email
●

Sending the user straight to G-Mail:
Intent i = new Intent(Intent.ACTION_SENDTO);
i.setType("text/html");
i.setData(Uri.parse("mailto:xxx@abc.com"));
startActivity(i);

●

Adding preset subject and message:
i.putExtra(Intent.EXTRA_SUBJECT, “abc”);
i.putExtra(Intent.EXTRA_TEXT, “abc”);
Email
●

Sending the user straight to G-Mail (simple):
i.setClassName("com.google.android.gm",
"com.google.android.gm.ConversationListActivity");
Camera : Permissions
●

Camera Permissions*
–

Use the device

<uses-permission
android:name= “android.permission.CAMERA”/>
●

Camera Features
–

Use camera features

<uses-permission
android:name= “android.hardware.camera”/>
Camera : Permissions
●

Storage Permissions*
–

The application saves images/videos to the
device's external storage

<uses-permission
android:name=
“android.permission.WRITE_EXTERNAL_STORAGE”/>
Camera : Coding
●

Our goal here is to
display the photo
taken by the user
when the camera
was called.
Camera : Coding
●

Logic
–

Because the shot photo is to be called back into
the activity:
●
●
●

–

Set up a directory for the image.
Get the output media file from that directory.
startActivityForResult() is to be called.

Use of Bitmap to show the image captured.
Global Variables
// Activity request codes
private static final int
CAMERA_CAPTURE_IMAGE_REQUEST_CODE = 100;
public static final int MEDIA_TYPE_IMAGE = 1;
// directory name to store the captured images
private static final String IMAGE_DIRECTORY_NAME =
"my_camera_app";
// file url to store image
private Uri fileUri;
Camera : Coding
●

Taking a picture:
private void captureImage() {
Intent intent = new
Intent(MediaStore.ACTION_IMAGE_CAPTURE);
fileUri = getOutputMediaFileUri(MEDIA_TYPE_IMAGE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri);
// start the image capture Intent
startActivityForResult(intent,
CAMERA_CAPTURE_IMAGE_REQUEST_CODE);
}

Instantiated using
helper methods
Activity for result
●

●

●

A method that is used when we would like to
receive something
Launch an activity and listen for results when
finished
When this activity exits, your
onActivityResult() method will be called with
the given requestCode
Activity for result
protected void onActivityResult(int requestCode, int resultCode,
Intent data) {
if (requestCode == CAMERA_CAPTURE_IMAGE_REQUEST_CODE) {
if (resultCode == RESULT_OK) {
// Successfully captured the image display in imageview
previewImage();
} else {
// failed to capture image
Toast.makeText(getApplicationContext(), "Sorry! Failed to
capture image", Toast.LENGTH_SHORT).show();
}
}
}
previewImage()
private void previewImage() {
try {
// Bitmap factory
BitmapFactory.Options options = new BitmapFactory.Options();
// Downsizing image as it throws OutOfMemory exception for
larger images
options.inSampleSize = 5;
final Bitmap bitmap =
BitmapFactory.decodeFile(fileUri.getPath(), options);
photo.setImageBitmap(bitmap);
} catch (NullPointerException e) {
e.printStackTrace();
}
}
Helper method
●

Get media file:
–

Setting the external sdcard location.

–

Checking on the storage directory(if it does not exist).

–

Naming the media.

–

Returning the media.

private static File getOutputMediaFile(int type) {
...
return mediaFile;
}
Get the media file
●

Setting up the external sdcard location:
File mediaStorageDir = new
File(Environment.getExternalStoragePublicDirec
tory(Environment.DIRECTORY_PICTURES),
IMAGE_DIRECTORY_NAME);

Directory path
Directory name to store
captured image, declared as a global variable.
Get the media file
●

Checking on the storage directory, if it does not
exist:
if (!mediaStorageDir.exists()) {
if (!mediaStorageDir.mkdirs()) {
Log.d(IMAGE_DIRECTORY_NAME, "Oops! Failed
create "+ IMAGE_DIRECTORY_NAME + "
directory");
return null;
}
}
Get the media file
●

Naming the media
File mediaFile;
if (type == MEDIA_TYPE_IMAGE) {
mediaFile = new
File(mediaStorageDir.getPath() +
File.separator + "IMG_" + ".jpg");
} else {
return null;
}
Get the media file
●
●

Finally, return the mediaFile.
Because this file is referred to from an URI,
the file is to be converted to an URI.
public Uri getOutputMediaFileUri(int type) {
return
Uri.fromFile(getOutputMediaFile(type));
}
Full code: http://bit.ly/1gIVSOS
For further reference: http://bit.ly/1bSk4MH
GPS
●

Permission:
<uses-permission android:name=
“android.permission.ACCESS_FINE_LOCATION”/>

●

Coding
–

–

Objective : Check if GPS is on or not.
● Call on the GPS settings intent.
If on, show coordinates.
● Call the location manager.
Call on the GPS settings
●

Intent GPSSettingIntent = new
Intent(android.provider.Settings.ACTION_LOCATI
ON_SOURCE_SETTINGS);
LocationManager
●

●

This class provides access to the system location
services.
These services allow applications:
–

–

●

to obtain periodic updates of the device's geographical
location.
to fire an application-specified Intent when the device
enters the proximity of a given geographical
location.

We instantiate LocationManager through:
Context.getSystemService(Context.LOCATION_SERVICE)
LocationManager
●

Checking to see if the location provider is enabled or
not:
if(locationManager.isProviderEnabled(LocationMana
ger.GPS_PROVIDER))

●

Fetch the location using the getLastKnowLocation():
Location location =
locationManager.getLastKnownLocation(LocationMana
ger.GPS_PROVIDER);
double latitude = location.getLatitude();
double longitude = location.getLongitude();

Full code: http://bit.ly/1i8YyEs

More Related Content

ODP
Android training day 4
ODP
Android training day 5
ODP
Android training day 2
PDF
ODP
Day seven
ODP
Session 2- day 3
PPTX
Angular2 + rxjs
PDF
Commit University - Exploring Angular 2
Android training day 4
Android training day 5
Android training day 2
Day seven
Session 2- day 3
Angular2 + rxjs
Commit University - Exploring Angular 2

What's hot (20)

PDF
Advanced Dagger talk from 360andev
PDF
An introduction to Angular2
PPTX
Angular modules in depth
PPTX
React render props
PDF
Workshop 20: ReactJS Part II Flux Pattern & Redux
PPTX
Extend sdk
PDF
Angular2 workshop
PPTX
Angular Workshop_Sarajevo2
PPTX
React outbox
PDF
준비하세요 Angular js 2.0
PDF
React native app with type script tutorial
PPT
GWT Training - Session 2/3
PDF
Workshop 19: ReactJS Introduction
PDF
Anton Minashkin Dagger 2 light
PDF
Speed up your GWT coding with gQuery
PDF
Speed up the site building with Drupal's Bootstrap Layout Builder
PPTX
Migrating an application from Angular 1 to Angular 2
PDF
Data Flow Patterns in Angular 2 - Sebastian Müller
PDF
Droidcon2013 pro guard, optimizer and obfuscator in the android sdk_eric lafo...
Advanced Dagger talk from 360andev
An introduction to Angular2
Angular modules in depth
React render props
Workshop 20: ReactJS Part II Flux Pattern & Redux
Extend sdk
Angular2 workshop
Angular Workshop_Sarajevo2
React outbox
준비하세요 Angular js 2.0
React native app with type script tutorial
GWT Training - Session 2/3
Workshop 19: ReactJS Introduction
Anton Minashkin Dagger 2 light
Speed up your GWT coding with gQuery
Speed up the site building with Drupal's Bootstrap Layout Builder
Migrating an application from Angular 1 to Angular 2
Data Flow Patterns in Angular 2 - Sebastian Müller
Droidcon2013 pro guard, optimizer and obfuscator in the android sdk_eric lafo...
Ad

Similar to Day 6 (20)

PDF
Android securitybyexample
PPTX
Msbte__________________CHPter_6_MAD.pptx
PPTX
Android101 - Intro and Basics
PDF
Android Workshop 2013
PDF
android level 3
PDF
Securing android applications
PPT
Ruby conf2012
PPTX
Simple Android Project (SAP)... A Test Application
PDF
Something about Intents and URI permissions
PDF
Android Telephony Manager and SMS
PPTX
MAD Unit 6.pptx
PDF
Scoped storage in android 10 all you need to know
PPTX
Android Marshmallow APIs and Changes
PDF
Introduction to Android - Mobile Portland
PPTX
Android
PDF
600.250 UI Cross Platform Development and the Android Security Model
PPT
Synapseindia android application development tutorial
PPT
Synapseindia android apps development tutorial
PPTX
Android - Intents and Filters hgfh gfh.pptx
DOCX
Using intents in android
Android securitybyexample
Msbte__________________CHPter_6_MAD.pptx
Android101 - Intro and Basics
Android Workshop 2013
android level 3
Securing android applications
Ruby conf2012
Simple Android Project (SAP)... A Test Application
Something about Intents and URI permissions
Android Telephony Manager and SMS
MAD Unit 6.pptx
Scoped storage in android 10 all you need to know
Android Marshmallow APIs and Changes
Introduction to Android - Mobile Portland
Android
600.250 UI Cross Platform Development and the Android Security Model
Synapseindia android application development tutorial
Synapseindia android apps development tutorial
Android - Intents and Filters hgfh gfh.pptx
Using intents in android
Ad

More from Vivek Bhusal (9)

PDF
Training Session 2 - Day 2
PDF
Training Session 2
PDF
Android training day 3
ODP
Android training day 1
PPTX
Stores munk presentation_aug10 (1)
PPTX
Mybudget
PDF
Wisevote - opendataweek @
PDF
Android training at GDG kathmandu Startup weekend bootcamp
PPTX
My medical info
Training Session 2 - Day 2
Training Session 2
Android training day 3
Android training day 1
Stores munk presentation_aug10 (1)
Mybudget
Wisevote - opendataweek @
Android training at GDG kathmandu Startup weekend bootcamp
My medical info

Recently uploaded (20)

PPTX
Understanding_Digital_Forensics_Presentation.pptx
PPTX
A Presentation on Artificial Intelligence
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Encapsulation theory and applications.pdf
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Electronic commerce courselecture one. Pdf
PPTX
Cloud computing and distributed systems.
PDF
Review of recent advances in non-invasive hemoglobin estimation
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PPTX
Big Data Technologies - Introduction.pptx
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Understanding_Digital_Forensics_Presentation.pptx
A Presentation on Artificial Intelligence
Building Integrated photovoltaic BIPV_UPV.pdf
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Encapsulation theory and applications.pdf
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Dropbox Q2 2025 Financial Results & Investor Presentation
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Diabetes mellitus diagnosis method based random forest with bat algorithm
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Electronic commerce courselecture one. Pdf
Cloud computing and distributed systems.
Review of recent advances in non-invasive hemoglobin estimation
20250228 LYD VKU AI Blended-Learning.pptx
Mobile App Security Testing_ A Comprehensive Guide.pdf
Big Data Technologies - Introduction.pptx
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Encapsulation_ Review paper, used for researhc scholars
Build a system with the filesystem maintained by OSTree @ COSCUP 2025

Day 6

  • 1. Android APIs: Phone, Camera, SMS, GPS, Email
  • 2. Using Permissions ● ● ● A basic android application has no permission associated with it by default. To make use of the protected features of the device we declare the <uses-permissions> in our manifest file. Permissions are granted by the users when the application is installed, not while it's running.
  • 3. Using Permissions ● Attributes: – android:name ● ● The name of the permission. android.permission.CAMERA, etc. For more: http://bit.ly/19g9vw0 android:maxSdkVersion ● – ● ● The highest API level at which the permission should be granted to your app. Optional to declare.
  • 4. Accessing in-built features ● We always use Intent for this purpose. ● We have separate ids for these features: – – ● Intent.ACTION_VIEW Intent.ACTION_SEND Use of other methods, like: – intent.setType() – intent.setData() are also seen.
  • 5. Phone Call ● Permission: <uses-permission android:name= “android.permission.CALL_PHONE”/> ● Code: Intent i = new Intent(Intent.ACTION_CALL); i.setData(Uri.parse(“tel:980XXXXXXX”)); startActivity(i);
  • 6. Phone Call ● If you just want to direct the user to his/her dialer: Intent i = new Intent(Intent.ACTION_DIAL); startActivity(i); ● No permissions required here.
  • 7. SMS ● Code: Intent i = new Intent(Intent.ACTION_VIEW); i.setData(Uri.parse("smsto:980XXXXXXX")); startActivity(i); ● No permissions here.
  • 8. SMS ● What if I want to send a message to a user from my application ?? – Use SmsManager. ● – ● Manages SMS operations such as sending data, text SMS messages. Get this object by calling the static method getDefault(). Permission: <uses-permission android:name= “android.permission.SEND_SMS”/>
  • 9. SMS ● private void sendSMS(String phoneNumber, String message) { String SENT = "SMS_SENT"; String DELIVERED = "SMS_DELIVERED"; Message and to which toSend.putExtra("number", phoneNumber); number is it to be sent Intent toSend = new Intent(SENT); PendingIntent sentPI = PendingIntent.getBroadcast(this, 0, toSend, 0); PendingIntent deliveredPI = PendingIntent.getBroadcast(this, 0, new Intent(DELIVERED), 0); SmsManager smsManager = SmsManager.getDefault(); smsManager.sendTextMessage(phoneNumber, null, message, sentPI, deliveredPI); } Actual work is done
  • 10. SMS ● What is PendingIntent ? – Because sending SMS is not our app's function, the Intent call is forwarded to a foreign application (to our default messaging app). – Using pending intents we specify an action to take in the future using the same permissions as your application.
  • 11. sendTextMessage() ● The parameters to provide are: – First parameter: Destination number/address. – Second parameter: Source number/address. – Third parameter: The message to be sent – Forth parameter: Pending intent/sent intent. – Fifth parameter: Pending intent/delivery intent (was the message delivered?)
  • 12. Email ● Permission: <uses-permission= “android.permission.INTERNET”/> ● Coding: Intent i = new Intent(Intent.ACTION_SEND); i.setType("text/plain"); startActivity(i);
  • 13. Email ● Sending the user straight to G-Mail: Intent i = new Intent(Intent.ACTION_SENDTO); i.setType("text/html"); i.setData(Uri.parse("mailto:xxx@abc.com")); startActivity(i); ● Adding preset subject and message: i.putExtra(Intent.EXTRA_SUBJECT, “abc”); i.putExtra(Intent.EXTRA_TEXT, “abc”);
  • 14. Email ● Sending the user straight to G-Mail: Intent i = new Intent(Intent.ACTION_SENDTO); i.setType("text/html"); i.setData(Uri.parse("mailto:xxx@abc.com")); startActivity(i); ● Adding preset subject and message: i.putExtra(Intent.EXTRA_SUBJECT, “abc”); i.putExtra(Intent.EXTRA_TEXT, “abc”);
  • 15. Email ● Sending the user straight to G-Mail (simple): i.setClassName("com.google.android.gm", "com.google.android.gm.ConversationListActivity");
  • 16. Camera : Permissions ● Camera Permissions* – Use the device <uses-permission android:name= “android.permission.CAMERA”/> ● Camera Features – Use camera features <uses-permission android:name= “android.hardware.camera”/>
  • 17. Camera : Permissions ● Storage Permissions* – The application saves images/videos to the device's external storage <uses-permission android:name= “android.permission.WRITE_EXTERNAL_STORAGE”/>
  • 18. Camera : Coding ● Our goal here is to display the photo taken by the user when the camera was called.
  • 19. Camera : Coding ● Logic – Because the shot photo is to be called back into the activity: ● ● ● – Set up a directory for the image. Get the output media file from that directory. startActivityForResult() is to be called. Use of Bitmap to show the image captured.
  • 20. Global Variables // Activity request codes private static final int CAMERA_CAPTURE_IMAGE_REQUEST_CODE = 100; public static final int MEDIA_TYPE_IMAGE = 1; // directory name to store the captured images private static final String IMAGE_DIRECTORY_NAME = "my_camera_app"; // file url to store image private Uri fileUri;
  • 21. Camera : Coding ● Taking a picture: private void captureImage() { Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); fileUri = getOutputMediaFileUri(MEDIA_TYPE_IMAGE); intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri); // start the image capture Intent startActivityForResult(intent, CAMERA_CAPTURE_IMAGE_REQUEST_CODE); } Instantiated using helper methods
  • 22. Activity for result ● ● ● A method that is used when we would like to receive something Launch an activity and listen for results when finished When this activity exits, your onActivityResult() method will be called with the given requestCode
  • 23. Activity for result protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == CAMERA_CAPTURE_IMAGE_REQUEST_CODE) { if (resultCode == RESULT_OK) { // Successfully captured the image display in imageview previewImage(); } else { // failed to capture image Toast.makeText(getApplicationContext(), "Sorry! Failed to capture image", Toast.LENGTH_SHORT).show(); } } }
  • 24. previewImage() private void previewImage() { try { // Bitmap factory BitmapFactory.Options options = new BitmapFactory.Options(); // Downsizing image as it throws OutOfMemory exception for larger images options.inSampleSize = 5; final Bitmap bitmap = BitmapFactory.decodeFile(fileUri.getPath(), options); photo.setImageBitmap(bitmap); } catch (NullPointerException e) { e.printStackTrace(); } }
  • 25. Helper method ● Get media file: – Setting the external sdcard location. – Checking on the storage directory(if it does not exist). – Naming the media. – Returning the media. private static File getOutputMediaFile(int type) { ... return mediaFile; }
  • 26. Get the media file ● Setting up the external sdcard location: File mediaStorageDir = new File(Environment.getExternalStoragePublicDirec tory(Environment.DIRECTORY_PICTURES), IMAGE_DIRECTORY_NAME); Directory path Directory name to store captured image, declared as a global variable.
  • 27. Get the media file ● Checking on the storage directory, if it does not exist: if (!mediaStorageDir.exists()) { if (!mediaStorageDir.mkdirs()) { Log.d(IMAGE_DIRECTORY_NAME, "Oops! Failed create "+ IMAGE_DIRECTORY_NAME + " directory"); return null; } }
  • 28. Get the media file ● Naming the media File mediaFile; if (type == MEDIA_TYPE_IMAGE) { mediaFile = new File(mediaStorageDir.getPath() + File.separator + "IMG_" + ".jpg"); } else { return null; }
  • 29. Get the media file ● ● Finally, return the mediaFile. Because this file is referred to from an URI, the file is to be converted to an URI. public Uri getOutputMediaFileUri(int type) { return Uri.fromFile(getOutputMediaFile(type)); } Full code: http://bit.ly/1gIVSOS For further reference: http://bit.ly/1bSk4MH
  • 30. GPS ● Permission: <uses-permission android:name= “android.permission.ACCESS_FINE_LOCATION”/> ● Coding – – Objective : Check if GPS is on or not. ● Call on the GPS settings intent. If on, show coordinates. ● Call the location manager.
  • 31. Call on the GPS settings ● Intent GPSSettingIntent = new Intent(android.provider.Settings.ACTION_LOCATI ON_SOURCE_SETTINGS);
  • 32. LocationManager ● ● This class provides access to the system location services. These services allow applications: – – ● to obtain periodic updates of the device's geographical location. to fire an application-specified Intent when the device enters the proximity of a given geographical location. We instantiate LocationManager through: Context.getSystemService(Context.LOCATION_SERVICE)
  • 33. LocationManager ● Checking to see if the location provider is enabled or not: if(locationManager.isProviderEnabled(LocationMana ger.GPS_PROVIDER)) ● Fetch the location using the getLastKnowLocation(): Location location = locationManager.getLastKnownLocation(LocationMana ger.GPS_PROVIDER); double latitude = location.getLatitude(); double longitude = location.getLongitude(); Full code: http://bit.ly/1i8YyEs