Vladimir Vladimir - 1 month ago 7
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;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

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

callConnection();
}


private synchronized void callConnection() {
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addOnConnectionFailedListener(this)
.addConnectionCallbacks(this)
.addApi(LocationServices.API)
.build();
mGoogleApiClient.connect();


}

String msg4;



@Override
public void onConnected(Bundle bundle) {

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



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

Location l = LocationServices
.FusedLocationApi
.getLastLocation(mGoogleApiClient);

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);
resultado.setText(msg4);
}
}

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

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



public void enviardados(View view) {
Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
sharingIntent.setType("text/plain");
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"));
}


}

Answer

get the string from textview and not its object

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