Home > Net >  How to share a photo from gallery to xamarin app
How to share a photo from gallery to xamarin app

Time:05-18

I'm looking for a way to share a photo from the gallery using the "forward to" function and make my xamarin app appear among those available as whatapp or instagram

CodePudding user response:

You can use Xamarin.Essentials: Share to achieve this.

The Share class enables an application to share data such as text and web links to other applications on the device.

Xamarin.Essentials will automatically detect the file type (MIME) and request a share. Each platform may only support specific file extensions.

Here is a sample of writing text to disk and sharing it to other apps:

var fn =  "Attachment.txt";
var file = Path.Combine(FileSystem.CacheDirectory, fn);
File.WriteAllText(file, "Hello World");

await Share.RequestAsync(new ShareFileRequest
{
    Title = Title,
    File = new ShareFile(file)
});

For more,you can check:

https://docs.microsoft.com/en-us/xamarin/essentials/share?tabs=android . https://github.com/harshitgindra/ImageShare.Xamarin

And there is similar threads about this, you can check them here:

Sharing an image using Xamarin Forms

  • Related