1

I want to share my location to a Whatsapp contact.

I don't know what is the mimeType that I have to use. This is the code I'm usign to share:

Intent waIntent = new Intent(Intent.ACTION_SEND);
waIntent.setPackage("com.whatsapp");
waIntent.setType("text/plain");
waIntent.putExtra(Intent.EXTRA_TEXT, "geo:23.1097,-82.4094");
startActivity(waIntent);

But this only send a plain text, not a location like Whatsapp does. Any idea??

1 Answers1

0

Note: I donot have (and dont want to have) Whatsapp but maybe my findings help you

since "geo:..." is a uri (defined here) you should wrap it into a Uri and send it as data.

This code works with other location aware android apps like GoogleMaps

String uriString = "geo:23.1097,-82.4094";

Intent waIntent = new Intent();
// waIntent.setPackage("com.whatsapp");
Uri uri = Uri.parse(uriString);

waIntent.setData(uri); // finds several apps on my phone including googleMaps
// waIntent.setDataAndType(uri, "*/*"); // does not work on my phone: nothing found
Toast.makeText(this, appName + "Starting " + uriString, Toast.LENGTH_SHORT).show();

try {
    this.startActivity(Intent.createChooser(waIntent,"Choose app to show location"));
} catch (Exception e) {
    Toast.makeText(this, appName + e.getMessage(), Toast.LENGTH_SHORT).show();
    e.printStackTrace();
}

You can check if whatsapp understand this, too

Community
  • 1
  • 1
k3b
  • 14,517
  • 7
  • 53
  • 85