0
我必須通過短信發送我的GPS座標,我怎樣才能在SMS身體的經度和緯度值? 我嘗試了一些東西,但我不能使用+ @ id/lat或+ String.valueOf(location.getLongitude()in intent.putExtra(「sms_body」,「將會有經度和緯度值..」);我如何使用我的GPS座標通過SMS身體android
這裏是SmsActivity.java
public class SmsActivity extends MainActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button button1 = (Button) findViewById(R.id.button1);
EditText editText = (EditText)findViewById(R.id.telNo);
final String telNo = editText.getText().toString();
button1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Uri uri = Uri.parse("smsto:" +telNo);
Intent intent = new Intent(Intent.ACTION_SENDTO,uri);
intent.putExtra("sms_body","there would be latitude and longitude values..");
startActivity(intent);
finish();
}
});
};
}
這裏是MainActivity.java
latitude = (TextView) findViewById(R.id.lat);
longitude = (TextView) findViewById(R.id.lon);
provText = (TextView) findViewById(R.id.prov);
choice = (TextView) findViewById(R.id.choice);
fineAcc = (CheckBox) findViewById(R.id.fineAccuracy);
choose = (Button) findViewById(R.id.chooseRadio);
// Get the location manager
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
// Define the criteria how to select the location provider
criteria = new Criteria();
criteria.setAccuracy(Criteria.ACCURACY_COARSE); //default
// user defines the criteria
choose.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if(fineAcc.isChecked()){
criteria.setAccuracy(Criteria.ACCURACY_FINE);
choice.setText("fine accuracy selected");
}else {
criteria.setAccuracy(Criteria.ACCURACY_COARSE);
choice.setText("coarse accuracy selected");
}
}
});
criteria.setCostAllowed(false);
// get the best provider depending on the criteria
provider = locationManager.getBestProvider(criteria, false);
// the last known location of this provider
Location location = locationManager.getLastKnownLocation(provider);
mylistener = new MyLocationListener();
if (location != null) {
mylistener.onLocationChanged(location);
} else {
// leads to the settings because there is no last known location
// Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
// startActivity(intent);
}
// location updates: at least 1 meter and 200millsecs change
locationManager.requestLocationUpdates(provider, 200, 1, mylistener);
}
private class MyLocationListener implements LocationListener {
@Override
public void onLocationChanged(Location location) {
// Initialize the location fields
latitude.setText("Latitude: "+String.valueOf(location.getLatitude()));
longitude.setText("Longitude: "+String.valueOf(location.getLongitude()));
我怎樣才能把經緯度值在SMS的身體嗎?
你可以分享的經度和緯度的代碼嗎? – 2014-12-27 16:12:38
它的location.getlatitude()和location.getlongitude(); – SK16 2014-12-27 16:13:25
謝謝,我會試試 – 2014-12-27 16:19:56