1

I using Xamarin to develop application.

How can I send picture via WhatsApp to number the I have in contact?

Buflow
  • 25
  • 2
  • You can refer to this link(https://stackoverflow.com/questions/68716565/c-sharp-xamarin-saving-image-and-sharing-on-whatsapp). – Wen xu Li Sep 06 '21 at 09:41

1 Answers1

0

The easiest way would be to use Xamarin.Essentials share API

This will not only give you an option for whatsapp but many other supported applications as well

You might need different permissions based on OS so make sure to go through the docs throughtly

Add the using statement:

using Xamarin.Essentials;

Get a file from the File system and share it :

await Share.RequestAsync(new ShareFileRequest
{
Title = Title,
File = new ShareFile(file),
PresentationSourceBounds = DeviceInfo.Platform== DevicePlatform.iOS && DeviceInfo.Idiom == DeviceIdiom.Tablet
                        ? new System.Drawing.Rectangle(0, 20, 0, 0)
                        : System.Drawing.Rectangle.Empty
});

Where File is the path of the file from your file system.

Goodluck let me know if you have any questions.

Make sure to check other amazing things available in Xamarin essentials.

UPDATE

Android:

        Intent share = new Intent();
        share.SetAction(Intent.ActionSend);
        share.SetType("image/jpeg");
        share.PutExtra(Intent.ExtraStream, yourImageUri);
        share.SetPackage("com.whatsapp");
        StartActivity(share);
FreakyAli
  • 13,349
  • 3
  • 23
  • 63