I have an application, in which I want to send my actual coordinates through email.
The code for opening a email client is the following:
final Button button = (Button) findViewById(R.id.addbutton);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
//Funktion aufrufen, aber ausserhalb definieren
Intent i = new Intent(Intent.ACTION_SENDTO);
//i.setType("message/rfc822");
i.setData(Uri.parse("mailto:"));
i.putExtra(Intent.EXTRA_EMAIL , new String[]{"mymail@example.com"});
i.putExtra(Intent.EXTRA_SUBJECT, "subject of email");
i.putExtra(Intent.EXTRA_TEXT , "body of email";
try {
startActivity(i);
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(MapsActivity.this, "There are no email clients installed.", Toast.LENGTH_SHORT).show();
}
}
});
The button
like this works fine.
Now I thought that I can define two variables with the actual latitude
and the other with the current longitude
.
For this purpose, I would have to get the actual coordinates.
So my question is: how can I put my current GPS coordinates in an email.
And please: keep the code as simple as possible :)
Edit:
I have this one: (which I don't really understand)
public void getLocation() {
LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);
}
and this one:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
getLocation();
}
@Override
public void onLocationChanged(Location location) {
double latitude = location.getLatitude();
double longitude = location.getLongitude();
location_lat = latitude;
location_long = longitude;
}