1

I am beginner at android. I have a question. I want to when I receive SMS then get my location(latitude and longitude). How can I do. if you have sample code, it will be more helpful.

Thanks for your help.

Mahmut EFE
  • 5,137
  • 5
  • 46
  • 56
  • 1
    You will have to write a broadcast receiver for Action - RECEIVE_SMS. In that you will have to implement LocationListener class and access location from that. – MysticMagicϡ Nov 21 '12 at 10:26

2 Answers2

4

For getting latitude and longitude when you have recived an sms on device you will need these steps:

STEP 1: Register an android.provider.Telephony.SMS_RECEIVED BroadcastReceiver for receiving incoming sms notification:

for this you can use following Tutorial :

http://androidsourcecode.blogspot.in/2010/10/receiving-sms-using-broadcastreceiver.html


STEP 2:

for retrieving location on sms received you will need to start an service (IntentService) in onReceive of SMS BroadcastReceiver as:

public class SmsReciever extends BroadcastReceiver {

 private static final String TAG = "Message recieved";

 @Override
 public void onReceive(Context context, Intent intent) {    
    if (intent.getAction().equals("android.provider.Telephony.SMS_RECEIVED")) {
      // Start your Location IntentService here 
             Intent i = new Intent(context, Location_Intent_Service.class);
            context.startService(i);
    }
 }

}


For How We use IntentService you can see following tutorial:

http://mobile.tutsplus.com/tutorials/android/android-fundamentals-intentservice-basics/


For how we Use LocationManager from Service class you can follow these Post:

Starting LocationManager as Service Android

Community
  • 1
  • 1
ρяσѕρєя K
  • 132,198
  • 53
  • 198
  • 213
1

please refer this example. I hope it helps you.

In this example the current location will be display and touched location will also display with lat-lon.

anddev
  • 3,144
  • 12
  • 39
  • 70