Exemplo n.º 1
0
        static Task PlatformRequestAsync(ShareMultipleFilesRequest request)
        {
            // load the data we need
            var contentUris = new List <IParcelable>(request.Files.Count);
            var contentType = default(string);

            foreach (var file in request.Files)
            {
                contentUris.Add(Platform.GetShareableFileUri(file));

                if (contentType == null)
                {
                    contentType = file.ContentType;
                }
                else if (contentType != file.ContentType)
                {
                    contentType = FileSystem.MimeTypes.All;
                }
            }

            var intentType = contentUris.Count > 1
                                ? Intent.ActionSendMultiple
                                : Intent.ActionSend;
            var intent = new Intent(intentType);

            intent.SetType(contentType);
            intent.SetFlags(ActivityFlags.GrantReadUriPermission);

            if (contentUris.Count > 1)
            {
                intent.PutParcelableArrayListExtra(Intent.ExtraStream, contentUris);
            }
            else if (contentUris.Count == 1)
            {
                intent.PutExtra(Intent.ExtraStream, contentUris[0]);
            }

            if (!string.IsNullOrEmpty(request.Title))
            {
                intent.PutExtra(Intent.ExtraTitle, request.Title);
            }

            var chooserIntent = Intent.CreateChooser(intent, request.Title ?? string.Empty);
            var flags         = ActivityFlags.ClearTop | ActivityFlags.NewTask;

            chooserIntent.SetFlags(flags);
            Platform.AppContext.StartActivity(chooserIntent);

            return(Task.CompletedTask);
        }
Exemplo n.º 2
0
        static Task PlatformOpenAsync(OpenFileRequest request)
        {
            var contentUri = Platform.GetShareableFileUri(request.File);

            var intent = new Intent(Intent.ActionView);

            intent.SetDataAndType(contentUri, request.File.ContentType);
            intent.SetFlags(ActivityFlags.GrantReadUriPermission);

            var chooserIntent = Intent.CreateChooser(intent, request.Title ?? string.Empty);
            var flags         = ActivityFlags.ClearTop | ActivityFlags.NewTask;

#if __ANDROID_24__
            if (Platform.HasApiLevelN)
            {
                flags |= ActivityFlags.LaunchAdjacent;
            }
#endif
            chooserIntent.SetFlags(flags);

            Platform.AppContext.StartActivity(chooserIntent);

            return(Task.CompletedTask);
        }
Exemplo n.º 3
0
        static Intent CreateIntent(EmailMessage message)
        {
            var action = (message?.Attachments?.Count ?? 0) switch
            {
                0 => Intent.ActionSendto,
                1 => Intent.ActionSend,
                _ => Intent.ActionSendMultiple
            };
            var intent = new Intent(action);

            if (action == Intent.ActionSendto)
            {
                intent.SetData(Uri.Parse("mailto:"));
            }
            else
            {
                intent.SetType(FileSystem.MimeTypes.EmailMessage);
            }

            if (!string.IsNullOrEmpty(message?.Body))
            {
                if (message.BodyFormat == EmailBodyFormat.Html)
                {
                    ISpanned html;
#if __ANDROID_24__
                    if (Platform.HasApiLevelN)
                    {
                        html = Html.FromHtml(message.Body, FromHtmlOptions.ModeLegacy);
                    }
                    else
#endif
                    {
#pragma warning disable CS0618 // Type or member is obsolete
                        html = Html.FromHtml(message.Body);
#pragma warning restore CS0618 // Type or member is obsolete
                    }
                    intent.PutExtra(Intent.ExtraText, html);
                }
                else
                {
                    intent.PutExtra(Intent.ExtraText, message.Body);
                }
            }
            if (!string.IsNullOrEmpty(message?.Subject))
            {
                intent.PutExtra(Intent.ExtraSubject, message.Subject);
            }
            if (message?.To?.Count > 0)
            {
                intent.PutExtra(Intent.ExtraEmail, message.To.ToArray());
            }
            if (message?.Cc?.Count > 0)
            {
                intent.PutExtra(Intent.ExtraCc, message.Cc.ToArray());
            }
            if (message?.Bcc?.Count > 0)
            {
                intent.PutExtra(Intent.ExtraBcc, message.Bcc.ToArray());
            }

            if (message?.Attachments?.Count > 0)
            {
                var uris = new List <IParcelable>();
                foreach (var attachment in message.Attachments)
                {
                    uris.Add(Platform.GetShareableFileUri(attachment));
                }

                if (uris.Count > 1)
                {
                    intent.PutParcelableArrayListExtra(Intent.ExtraStream, uris);
                }
                else
                {
                    intent.PutExtra(Intent.ExtraStream, uris[0]);
                }

                intent.AddFlags(ActivityFlags.GrantReadUriPermission);
            }

            return(intent);
        }
    }