问题
i am making a android project so can anyone tell me how do i send my current location in URL via SMS . Let me explain what i want to know when the mobile got a shake then my app sent a string SMS to selected contact now i want to add location feature in my app mean i want to send the location via URL in SMS ,when the receiver hit on URL then he can the location of sender in his map ?
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();
}
回答1:
I suggest you to get the current latitude
and longitude
of the device. The in step two you can create a String which is a searching url
with those parameters which looks like this
String message = "http://maps.google.com/?q=" + {latitude} + "," + {longitude}
And for the further info to get the current longitude
and latitude
have a look here
回答2:
normal way then you can insert a url as bellow:
String pos_url = "http://sharegps.com?lat=00000000000&long=00000000000"; // you can replace your real gps position and your domain (or use maps.google.com)
First way:
SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage(ph, null, pos_url, null, null);
Toast.makeText(getApplicationContext(), "SMS SENT",
Toast.LENGTH_LONG).show();
Second way:
private void shareTextUrl() {
Intent share = new Intent(android.content.Intent.ACTION_SEND);
share.setType("text/plain");
share.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
// Add data to the intent, the receiving app will decide
// what to do with it.
share.putExtra(Intent.EXTRA_SUBJECT, "Title Of The Post");
share.putExtra(Intent.EXTRA_TEXT, pos_url);
startActivity(Intent.createChooser(share, "Share location!"));
}
来源:https://stackoverflow.com/questions/35864253/how-do-i-send-my-location-via-url-in-sms