Sharing a location using Whatsapp from my app

In one of my applications, I am transferring latitude and logic from my application to whatsapp and want to share this location. I achieved this using this piece of code.

public void sendMessage() {
    String whatsAppMessage = "http://maps.google.com/maps?saddr=" + latitude + "," + longitude;
    Intent sendIntent = new Intent();
    sendIntent.setAction(Intent.ACTION_SEND);
    sendIntent.putExtra(Intent.EXTRA_TEXT, whatsAppMessage);
    sendIntent.setType("text/plain");
    sendIntent.setPackage("com.whatsapp");
    startActivity(sendIntent);
}

Everything is fine, as it gives me a location map from Google maps, and I can share the same. But I just want to know if there is anyway that I can share the location, like how whatsapp does it by default. I mean the card that Whatsapp uses. Please view the screenshot for a clear understanding. enter image description here. Any help is appreciated. Thanks in advance.

+4

Source: https://habr.com/ru/post/1672353/


All Articles