InTheHand.ApplicationModel.DataTransfer.DataTransferManager.ShowShareUI C# (CSharp) Method

ShowShareUI() public static method

Programmatically initiates the user interface for sharing content with another app.
public static ShowShareUI ( ) : void
return void
        public async static void ShowShareUI()
        {
            DataRequestedEventArgs e = new DataRequestedEventArgs();
            instance.OnDataRequested(e);
            instance.currentDataPackage = e.Request.Data;
            DataPackageView view = instance.currentDataPackage.GetView();

            if (view.AvailableFormats.Count > 0)
            {


                foreach (string format in view.AvailableFormats)
                {
                    Debug.WriteLine(format);
                }
#if __ANDROID__
                    string text = null;
                    if(view.Contains(StandardDataFormats.Text))
                    {
                        text = await view.GetTextAsync();
                    }
                    else if(view.Contains(StandardDataFormats.WebLink ))
                    {
                        text = (await view.GetWebLinkAsync()).ToString();
                    }
                    Intent shareIntent = new Intent();
                    shareIntent.SetAction(Intent.ActionSend);
                    shareIntent.AddFlags(ActivityFlags.ClearWhenTaskReset | ActivityFlags.NewTask);
                    shareIntent.PutExtra(Intent.ExtraText, text);
                    shareIntent.SetType("text/plain");
                    Intent shareChooserIntent = Intent.CreateChooser(shareIntent, "Share");
                    shareChooserIntent.AddFlags(ActivityFlags.ClearWhenTaskReset);
                Plugin.CurrentActivity.CrossCurrentActivity.Current.Activity.StartActivity(shareChooserIntent);
                //Platform.Android.ContextManager.Context.ApplicationContext.StartActivity(shareChooserIntent);
#elif __IOS__
                List<NSObject> values = new List<NSObject>();
                if (view.Contains(StandardDataFormats.WebLink))
                {
                    values.Add(new NSUrl((await view.GetWebLinkAsync()).ToString()));
                }
                else if (view.Contains(StandardDataFormats.Text))
                {
                    values.Add(new NSString(await view.GetTextAsync()));
                }
                else if (view.Contains(StandardDataFormats.ApplicationLink))
                {
                    values.Add(new NSUrl((await view.GetApplicationLinkAsync()).ToString()));
                }
                UIActivityViewController activity = new UIActivityViewController(values.ToArray(), null);
                activity.CompletionWithItemsHandler = (text, success, items, error) =>
                {
                    if (success)
                    {
                        instance.OnTargetApplicationChosen(text);
                    }
                    else
                    {
                        Debug.WriteLine(error);
                    }
                };
                UIViewController currentController = UIApplication.SharedApplication.KeyWindow.RootViewController;
                while (currentController.PresentedViewController != null)
                {
                    currentController = currentController.PresentedViewController;
                }
                currentController.PresentModalViewController(activity, true);
#elif WINDOWS_PHONE
                /*if (view.Contains(StandardDataFormats.Bitmap))
                {
                    string path = view.GetBitmapFilename();
                    if (string.IsNullOrEmpty(path))
                    {
                        System.IO.Stream /Windows.Storage.Streams.RandomAccessStreamReference/ strRef = await view.GetBitmapAsync();
                        Microsoft.Xna.Framework.Media.MediaLibrary ml = new Microsoft.Xna.Framework.Media.MediaLibrary();
                        Microsoft.Xna.Framework.Media.Picture pic = ml.SavePicture("share", strRef);
                        path = Microsoft.Xna.Framework.Media.PhoneExtensions.MediaLibraryExtensions.GetPath(pic);
                    }

                    Microsoft.Phone.Tasks.ShareMediaTask shareMediaTask = new Microsoft.Phone.Tasks.ShareMediaTask();
                    shareMediaTask.FilePath = path; // "isostore:///shared/shellcontent/share.temp." + filename + ".png";
                    shareMediaTask.Show();
                }
                else
                {*/

                // for 8.0 apps running on 8.1 provide "light-up" to use shell sharing feature
                if (Environment.OSVersion.Version >= new Version(8, 10))
                {
                    if (view.Contains(StandardDataFormats.WebLink))
                    {
                        Microsoft.Phone.Tasks.ShareLinkTask shareLinkTask = new Microsoft.Phone.Tasks.ShareLinkTask();
                        shareLinkTask.LinkUri = await view.GetWebLinkAsync();
                        shareLinkTask.Message = await view.GetTextAsync();
                        shareLinkTask.Title = view.Properties.Title;
                        shareLinkTask.Show();
                    }
                    else if (view.Contains(StandardDataFormats.ApplicationLink))
                    {
                        Microsoft.Phone.Tasks.ShareLinkTask shareLinkTask = new Microsoft.Phone.Tasks.ShareLinkTask();
                        shareLinkTask.LinkUri = await view.GetApplicationLinkAsync();
                        shareLinkTask.Message = await view.GetTextAsync();
                        shareLinkTask.Title = view.Properties.Title;
                        shareLinkTask.Show();
                    }
                    else if (view.Contains(StandardDataFormats.Text))
                    {
                        Microsoft.Phone.Tasks.ShareStatusTask shareStatusTask = new Microsoft.Phone.Tasks.ShareStatusTask();
                        shareStatusTask.Status = await view.GetTextAsync();
                        shareStatusTask.Show();
                    }
                }
                else
                {
                    // use "custom" page to match OS 8.0 support
                    ((Microsoft.Phone.Controls.PhoneApplicationFrame)Application.Current.RootVisual).Navigate(new Uri("/InTheHand.ApplicationModel;component/SharePage.xaml", UriKind.Relative));
                }
                    //}
#endif
            }


            else
            {
                // nothing to share
#if WINDOWS_PHONE
                //System.Windows.MessageBox.Show(Resources.Resources.NothingToShare, Resources.Resources.ShareHeader, MessageBoxButton.OK);
#endif

            }
        }