-1

i am developing a android app in which i need to send my current location via sms ,so can anyone please tell me how do i send my current location via sms as url to a selected contact , one more thing i want to tell is i am sending a string sms like help me , so i want to send the location with string sms to a selected contact , can anyone please tell me how can i do this?

 private void sendSMS(String ph, String message) {
        SmsManager smsManager = SmsManager.getDefault();
        smsManager.sendTextMessage(ph, null, message,  null, null);
        Toast.makeText(getApplicationContext(), "SMS SENT",
                Toast.LENGTH_LONG).show();
    }
Abhishek
  • 686
  • 6
  • 17

1 Answers1

1

try below code

public void sendLocationSMS(String phoneNumber, Location currentLocation) {
SmsManager smsManager = SmsManager.getDefault();
StringBuffer smsBody = new StringBuffer();
smsBody.append("http://maps.google.com?q="); 
smsBody.append(currentLocation.getLatitude());
smsBody.append(",");
smsBody.append(currentLocation.getLongitude());
smsManager.sendTextMessage(phoneNumber, null, smsBody.toString(), null, null);
}

Below link shows an example to get your current location

How to get current location in Android

Community
  • 1
  • 1
Meenal
  • 2,914
  • 5
  • 18
  • 43