1

I have some problem witch sharing PDF file (in xamarin android). I'm using iTextSharp for generate pdf, after that i'm saving file to path: "/data/user/0/com.example/files/confirmation.pdf", and now i can display this pdf - everything works good, but now i'm trying to share this pdf:

        var intent = new Intent(Intent.ActionSend);
        intent.SetType("application/pdf");

        Java.IO.File file = new Java.IO.File("/data/user/0/com.example/files/confirmation.pdf");
        Android.Net.Uri path = Android.Net.Uri.FromFile(file);

        intent.PutExtra(Intent.ExtraStream, path);

        intent.PutExtra(Intent.ExtraText, string.Empty);
        intent.PutExtra(Intent.ExtraSubject, message ?? string.Empty);


        var chooserIntent = Intent.CreateChooser(intent, title ?? string.Empty);
        chooserIntent.SetFlags(ActivityFlags.ClearTop);
        chooserIntent.SetFlags(ActivityFlags.NewTask);

        _context.StartActivity(chooserIntent);

Now i can chose how to share file, and when i'm picking "Gmail", gmail shows with warning "Permission denied for the attachment". How can i deal with this?

  • You can to pass a content provider-based (`content:\\...`) url and|or (depending upon Android API level) make sure that your app has a "file provider" that provides access to that path within your app to external apps. Some examples are in this issue: https://github.com/xamarin/Essentials/issues/130#issuecomment-377087344 – SushiHangover Mar 26 '19 at 21:21

0 Answers0