示例#1
0
        protected override async void OnActivityResult(int requestCode, Result resultCode, Intent data)
        {
            if (resultCode == Result.Canceled || (!(requestCode == SelectPhotoPlatform || requestCode == SelectPhotoPcl)))
            {
                return;
            }

            MediaFile mediaFile = await data.GetMediaFileExtraAsync(this);

            if (mediaFile != null)
            {
                IEmailMessage email;
                if (requestCode == SelectPhotoPlatform)
                {
                    File file = new File(mediaFile.Path);
                    email = SamplesExtensions.BuildSampleEmail()
                            .WithAttachment(file)
                            .Build();
                }
                else
                {
                    // Hard coded mimetype for sample. Should really use Media Query to resolve at run-time
                    email = SamplesExtensions.BuildSampleEmail()
                            .WithAttachment(mediaFile.Path, @"image/jpeg")
                            .Build();
                }

                CrossMessaging.Current.EmailMessenger.SendSampleEmail(email);
            }
        }
        private async void ButtonSendAttachmentsEmail_OnClick(object sender, RoutedEventArgs e)
        {
            // NOTE: The calling app will be suspended and re-activated once the user has selected
            // a photo. To handle the selection of the photo, implement the IFileOpenPickerContinuable
            // on the Page that launched the SelectPicture call (see DeviceTaskApp for sample code)

            var openPicker = new FileOpenPicker();

            openPicker.ViewMode = PickerViewMode.Thumbnail;
            openPicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
            openPicker.FileTypeFilter.Add(".jpg");
            openPicker.FileTypeFilter.Add(".jpeg");
            openPicker.FileTypeFilter.Add(".png");

            IStorageFile file = await openPicker.PickSingleFileAsync();

            if (file != null)
            {
                var email = SamplesExtensions.BuildSampleEmail()
                            .WithAttachment(file)
                            .Build();

                CrossMessaging.Current.EmailMessenger.SendSampleEmail(email);
            }
        }
        private async Task SendAttachmentsEmail(bool usePlatformApi = true)
        {
            var       mediaPicker = new MediaPicker();
            MediaFile mediaFile   = await mediaPicker.PickPhotoAsync();

            if (mediaFile != null)
            {
                IEmailMessage email;
                if (usePlatformApi)
                {
                    NSUrl url = new NSUrl(mediaFile.Path, false);
                    email = SamplesExtensions.BuildSampleEmail()
                            .WithAttachment(url)
                            .Build();
                }
                else
                {
                    // Hard coded mimetype for sample. Should query file to determine at run-time
                    email = SamplesExtensions.BuildSampleEmail()
                            .WithAttachment(mediaFile.Path, @"image/jpeg")
                            .Build();
                }

                CrossMessaging.Current.EmailMessenger.SendSampleEmail(email);
            }
        }
示例#4
0
        private static async Task SendAttachmentEmail(bool usePlatformApi = true)
        {
            var openPicker = new FileOpenPicker();

            openPicker.ViewMode = PickerViewMode.Thumbnail;
            openPicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
            openPicker.FileTypeFilter.Add(".jpg");
            openPicker.FileTypeFilter.Add(".jpeg");
            openPicker.FileTypeFilter.Add(".png");

            IStorageFile file = await openPicker.PickSingleFileAsync();

            if (file != null)
            {
                IEmailMessage email;
                if (usePlatformApi)
                {
                    email = SamplesExtensions.BuildSampleEmail()
                            .WithAttachment(file)
                            .Build();

                    CrossMessaging.Current.EmailMessenger.SendSampleEmail(email);
                }
                else
                {
                    // On Windows, apps cannot access files by unless they reside in ApplicationData so the following won't work.
                    //email = SamplesExtensions.BuildSampleEmail()
                    //    .WithAttachment(file.Path, file.ContentType)
                    //    .Build();
                }
            }
        }
        public void ContinueFileOpenPicker(FileOpenPickerContinuationEventArgs args)
        {
            if (args.Files.Count > 0)
            {
                var email = SamplesExtensions.BuildSampleEmail()
                            .WithAttachment(args.Files[0])
                            .Build();

                MessagingPlugin.EmailMessenger.SendSampleEmail(email);
            }
        }
        public void ContinueFileOpenPicker(FileOpenPickerContinuationEventArgs args)
        {
            if (args.Files.Count > 0)
            {
                IStorageFile file  = args.Files[0];
                var          email = SamplesExtensions.BuildSampleEmail()
                                     .WithAttachment(file)
                                     .Build();

                CrossMessaging.Current.EmailMessenger.SendSampleEmail(email);
            }
        }
        protected async override void OnActivityResult(int requestCode, Result resultCode, Intent data)
        {
            if (resultCode == Result.Canceled || requestCode != SelectPhoto)
            {
                return;
            }

            MediaFile file = await data.GetMediaFileExtraAsync(this);

            var email = SamplesExtensions.BuildSampleEmail()
                        .WithAttachment(file.Path)
                        .Build();

            MessagingPlugin.EmailMessenger.SendSampleEmail(email);
        }
        private async void ButtonSendAttachmentsEmail_TouchUpInside(object o, EventArgs eventArgs)
        {
            var       mediaPicker = new MediaPicker();
            MediaFile file        = await mediaPicker.PickPhotoAsync();

            if (file != null)
            {
                var fileName = System.IO.Path.GetFileName(file.Path);

                // Assume image content is default jpeg
                var email = SamplesExtensions.BuildSampleEmail()
                            .WithAttachment(fileName, file.GetStream(), "image/jpeg")
                            .Build();

                MessagingPlugin.EmailMessenger.SendSampleEmail(email);
            }
        }