I have found current location's address,i have to share it.. i am trying to share by the use of putExtra function.Can u guide me? I am sharing my code to share that obtained address of the current location.. what change do I need to make in my code to accomplish this?
protected void onRestart() {
super.onRestart();
gps = new GpsTracker(this);
open();
}
@Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
if (gps.canGetLocation()) {
sd.setVisibility(View.VISIBLE);
}
open();
locationshare();
}
private void open() {
location.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
show();
add();
}
});
}
private void locationshare() {
share.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
display();
}
});
}
public void show() {
String stringLatitude = String.valueOf(gps.latitude);
String stringLongitude = String.valueOf(gps.longitude);
latitude.setText("Latitude :" + stringLatitude);
longitude.setText("Longitude :" + stringLongitude);
}
public void add() {
geocoder = new Geocoder(this, Locale.ENGLISH);
try {
List<Address> addresses = geocoder.getFromLocation(gps.latitude,
gps.longitude, 1);
if (addresses.size() > 0) {
Address returnedAddress = addresses.get(0);
StringBuilder strReturnedAddress = new StringBuilder(
"Address:\n");
for (int i = 0; i < returnedAddress.getMaxAddressLineIndex(); i++) {
strReturnedAddress
.append(returnedAddress.getAddressLine(i)).append(
"\n");
}
address.setText(strReturnedAddress.toString());
} else {
address.setText("No Address returned!");
}
} catch (IOException e) {
e.printStackTrace();
address.setText("Canont get Address! Check Network Connection");
}
}
public void display() {
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT,
"Here display to obtained address");
sendIntent.putExtra(Intent.EXTRA_SUBJECT, "address");
sendIntent.setType("text/plain");
startActivity(Intent.createChooser(sendIntent, "Share Place via"));
}
}