xamarin.forms Share directly to platform

Viewed 97

Sharing in Xamarin.Forms usually goes something like:

public async Task ShareUri(string uri)
{
    await Share.RequestAsync(new ShareTextRequest
        {
            Uri = uri,
            Title = "Share Web Link"
        });
}

But this will just open the share interface. If I already have an interface set up to this, how can I share to a specific platform directly and cut out the middle man?

Any ideas?

Than you!

1 Answers

There is a level of 'it depends' on what you can based on what exactly you plan to do with the sharing. If you are planning on adding the content (text, image, etc.) to the clipboard or you know the url scheme of the app you wish to share with then this will be entirely within your control (e.g. for copying just use Xamarin.Essentials.Clipboard or for opening another app just use Xamarin.Essentials.Launcher.

Note that the current approach you referred to Share.RequestAsync provides a lot of the heavy lifting around knowing which apps are on the device that will accept the content type you wish to share. This is managed by the operating system of the device and therefore uses it's built in UI to provide the sharing options. I do not believe there is a way to perform the actual sharing without using this and if you did manage to find a way you would want to double check that Apple and Google would accept such an approach when it comes to review time.

Related