Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

Xamarin Forms: Sharing Images Through Native picker

$
0
0

I am trying to share an image with an android picker through a dependency service but no images ever make it through to the application that is selected. The applications that are opened successfully just give a toast message stating "The attachment could not be loaded." Can someone please share why this piece of code could possibly be failing?

    public async Task ShareImageAndroid(string imageName)
    {
        var imagePath = "File:/" + DependencyService.Get<ImageCaching>().GetFilePath(imageName);
        Android.Net.Uri uri = Android.Net.Uri.Parse(imagePath);

        var sharingIntent = new Intent();
        sharingIntent.SetAction(Intent.ActionSend);
        sharingIntent.SetType("image/*");
        sharingIntent.PutExtra(Intent.ExtraText, "Image");
        sharingIntent.PutExtra(Intent.ExtraStream, uri);
        sharingIntent.AddFlags(ActivityFlags.GrantReadUriPermission);
        Forms.Context.StartActivity(Intent.CreateChooser(sharingIntent, "Make a Selection"));
    }

For clarification:
DependencyService.Get().GetFilePath(imageName);
This function returns the path of an image that has already been saved to external storage on the device.

Here is an example of a path that is returned: "/data/user/0/com.application.name/files/assets/image.png"


Viewing all articles
Browse latest Browse all 204402

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>