Vladimir Vladimir - 2 months ago 14
Android Question

Sharing only text android studio

I'm developing a test app (for learning) that gets the user location and then puts the location values in a string to be shared via email, etc...

The location code is working very well, but when the email interface is called, there is a lot of code coming together with, like this:

"Android.widget.TextView{f05b211V.ED.... ......ID 48,108-1032, 165 #7f0d0053 applied/tv_coordinate}"

How can I solve this and get only the correct values (latitude and longitude, in the case) shown?

Thank you all!

My code is as follows:

public class MainActivity extends ActionBarActivity
implements GoogleApiClient.ConnectionCallbacks,
GoogleApiClient.OnConnectionFailedListener {

private TextView tvCoordinate;
private GoogleApiClient mGoogleApiClient;

protected void onCreate(Bundle savedInstanceState) {

tvCoordinate = (TextView) findViewById(R.id.tv_coordinate);


private synchronized void callConnection() {
mGoogleApiClient = new GoogleApiClient.Builder(this)


String msg4;

public void onConnected(Bundle bundle) {

TextView resultado = (TextView) findViewById(R.id.result);

Log.i("LOG", "onConnected(" + bundle + ")");

Location l = LocationServices

if (l != null) {
Log.i("LOG", "latitude: " + l.getLatitude());
Log.i("LOG", "longitude: " + l.getLongitude());
tvCoordinate.setText(l.getLatitude() + " | " + l.getLongitude());

msg4 = String.format("%s", tvCoordinate);

public void onConnectionSuspended(int i) {
Log.i("LOG", "onConnectionSuspended(" + i + ")");

public void onConnectionFailed(ConnectionResult connectionResult) {
Log.i("LOG", "onConnectionFailed(" + connectionResult + ")");

public void enviardados(View view) {
Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
String shareBody = String.format("A localizacao e %s", msg4);
sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Localizacao");
sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, shareBody);
startActivity(Intent.createChooser(sharingIntent, "Compartilhar via"));



get the string from textview and not its object

        msg4 = String.format("%s", tvCoordinate.getText().toString());