Beispiel #1
0
        public Task <bool> Share(ShareMessage message, ShareOptions options = null)
        {
            if (message == null)
            {
                throw new ArgumentNullException(nameof(message));
            }

            try
            {
                title = message.Title;
                text  = message.Text;
                url   = message.Url;
                if (dataTransferManager == null)
                {
                    dataTransferManager = DataTransferManager.GetForCurrentView();
                    dataTransferManager.DataRequested += new TypedEventHandler <DataTransferManager, DataRequestedEventArgs>(this.ShareTextHandler);
                }
                DataTransferManager.ShowShareUI();

                return(Task.FromResult(true));
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Unable to share: " + ex.Message);
                return(Task.FromResult(false));
            }
        }
Beispiel #2
0
        public Task <bool> Share(ShareMessage message, ShareOptions options = null)
        {
            if (message == null)
            {
                throw new ArgumentNullException(nameof(message));
            }

            try
            {
                var items = new List <string>();
                if (message.Text != null)
                {
                    items.Add(message.Text);
                }
                if (message.Url != null)
                {
                    items.Add(message.Url);
                }

                var intent = new Intent(Intent.ActionSend);
                intent.SetType("text/plain");
                intent.PutExtra(Intent.ExtraText, string.Join(Environment.NewLine, items));
                if (message.Title != null)
                {
                    intent.PutExtra(Intent.ExtraSubject, message.Title);
                }

                var chooserIntent = Intent.CreateChooser(intent, options?.ChooserTitle);
                chooserIntent.SetFlags(ActivityFlags.ClearTop);
                chooserIntent.SetFlags(ActivityFlags.NewTask);
                Platform.CurrentContext.StartActivity(chooserIntent);

                return(Task.FromResult(true));
            }
            catch (Exception ex)
            {
                Console.WriteLine("Unable to share: " + ex.Message);
                return(Task.FromResult(false));
            }
        }
Beispiel #3
0
        private async Task <bool> Share(ShareMessage message, ShareOptions options = null, params NSString[] excludedActivityTypes)
        {
            if (message == null)
            {
                throw new ArgumentNullException(nameof(message));
            }

            try
            {
                // create activity items
                var items = new List <NSObject>();
                if (message.Text != null)
                {
                    items.Add(new ShareActivityItemSource(new NSString(message.Text), message.Title));
                }
                if (message.Url != null)
                {
                    items.Add(new ShareActivityItemSource(NSUrl.FromString(message.Url), message.Title));
                }

                // create activity controller
                var activityController = new UIActivityViewController(items.ToArray(), null);

                // set excluded activity types
                if (excludedActivityTypes == null)
                {
                    // use ShareOptions.ExcludedUIActivityTypes
                    excludedActivityTypes = options?.ExcludedUIActivityTypes?.Select(x => GetUIActivityType(x)).Where(x => x != null).ToArray();
                }

                if (excludedActivityTypes == null)
                {
                    // use ShareImplementation.ExcludedUIActivityTypes
                    excludedActivityTypes = ExcludedUIActivityTypes?.ToArray();
                }

                if (excludedActivityTypes != null && excludedActivityTypes.Length > 0)
                {
                    activityController.ExcludedActivityTypes = excludedActivityTypes;
                }

                // show activity controller
                var vc = GetVisibleViewController();

                if (UIDevice.CurrentDevice.CheckSystemVersion(8, 0))
                {
                    if (activityController.PopoverPresentationController != null)
                    {
                        activityController.PopoverPresentationController.SourceView = vc.View;

                        var rect = options?.PopoverAnchorRectangle;
                        if (rect != null)
                        {
                            activityController.PopoverPresentationController.SourceRect = new CGRect(rect.X, rect.Y, rect.Width, rect.Height);
                        }
                    }
                }

                await vc.PresentViewControllerAsync(activityController, true);

                return(true);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Unable to share: " + ex.Message);
                return(false);
            }
        }
Beispiel #4
0
 public Task <bool> Share(ShareMessage message, ShareOptions options = null)
 {
     throw new System.NotImplementedException();
 }
Beispiel #5
0
 public Task <bool> Share(ShareMessage message, ShareOptions options = null)
 {
     return(Share(message, options, null));
 }