void RequestSharePhoto(Dictionary <string, object> paramsDictionary)
        {
            if (paramsDictionary != null && paramsDictionary.ContainsKey("photo"))
            {
                var imageBytes             = paramsDictionary["photo"] as byte[];
                SharePhoto.Builder builder = new SharePhoto.Builder();
                if (paramsDictionary.ContainsKey("caption"))
                {
                    builder.SetCaption($"{paramsDictionary["caption"]}");
                }

                Bitmap bmp = BitmapFactory.DecodeByteArray(imageBytes, 0, imageBytes.Length);
                //Bitmap mutableBitmap = bmp.copy(Bitmap.Config.ARGB_8888, true);

                SharePhoto sharePhoto = builder.SetBitmap(bmp).Build().JavaCast <SharePhoto>();


                var photos = new List <SharePhoto>();
                photos.Add(sharePhoto);

                var sharePhotoContent = new SharePhotoContent.Builder()
                                        .SetPhotos(photos).Build();

                //ShareApi.Share(sharePhotoContent, shareCallback);

                ShareDialog dialog = new ShareDialog(CurrentActivity);
                dialog.RegisterCallback(mCallbackManager, shareCallback);
                dialog.ShouldFailOnDataError = true;
                dialog.Show(sharePhotoContent, ShareDialog.Mode.Automatic);
            }
        }
Example #2
0
        private static async Task ShareImageAsync(ImageSource image, string message)
        {
            var handler = image.GetHandler();

            if (handler == null)
            {
                return;
            }
            var activity = ((Android.App.Activity)Xamarin.Forms.Forms.Context);
            var bitmap   = await handler.LoadImageAsync(image, Android.App.Application.Context);

            System.Diagnostics.Debug.WriteLine("share image");
            ShareDialog shareDialog;
            Bitmap      dataimage = bitmap;

            try
            {
                SharePhoto        photo   = new SharePhoto.Builder().SetBitmap(dataimage).Build().JavaCast <SharePhoto>();
                SharePhotoContent content = new SharePhotoContent.Builder().AddPhoto(photo).Build();

                shareDialog = new ShareDialog(activity);
                shareDialog.Show(content, ShareDialog.Mode.Automatic);
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine("ERROR: e: " + e);
            };
        }
        //Lets user share current image
        private async void share_Click(object sender, RoutedEventArgs e)
        {
            //Get temp folder and create a new temp file
            var         localFolder = ApplicationData.Current.TemporaryFolder;
            StorageFile file        = await localFolder.CreateFileAsync("photo.jpg", CreationCollisionOption.ReplaceExisting);

            //http://stackoverflow.com/questions/22313245/save-canvas-from-windows-store-app-as-image-file
            var renderTargetBitmap = new RenderTargetBitmap();
            await renderTargetBitmap.RenderAsync(mainCanvas);

            var pixels = await renderTargetBitmap.GetPixelsAsync();

            using (IRandomAccessStream stream = await file.OpenAsync(FileAccessMode.ReadWrite))
            {
                var encoder = await
                              BitmapEncoder.CreateAsync(BitmapEncoder.JpegEncoderId, stream);

                byte[] bytes = pixels.ToArray();
                encoder.SetPixelData(BitmapPixelFormat.Bgra8,
                                     BitmapAlphaMode.Ignore,
                                     (uint)mainCanvas.ActualWidth, (uint)mainCanvas.ActualHeight,
                                     96, 96, bytes);

                await encoder.FlushAsync();
            }
            //Displays twitter/facebook share dialog
            var dialog = new ShareDialog(file);
            await dialog.ShowAsync();
        }
        public void ShareLinkOnFacebook(string text, string description, string link)
        {
            ShareLinkContent link1 = new ShareLinkContent();

            link1.SetContentUrl(new NSUrl(link));
            var shareDelegate = new FbDelegate();

            var dialog = new ShareDialog();

            dialog.Mode = ShareDialogMode.FeedBrowser;
            dialog.SetDelegate(shareDelegate);
            dialog.SetShareContent(link1);
            dialog.FromViewController = UIApplication.SharedApplication.KeyWindow.RootViewController;
            bool isInstalled = UIApplication.SharedApplication.CanOpenUrl(new NSUrl(urlString: "fb://"));

            if (isInstalled)
            {
                dialog.Mode = ShareDialogMode.Native;
                dialog.Show();
            }
            else
            {
                ShareAPI.Share(link1, shareDelegate);
            }
        }
 public static void SharePhotosOnFacebook(IEnumerable <byte[]> photos, string hashtag = null)
 {
     Thread.UI.Post(() =>
     {
         var content      = new SharePhotoContent();
         var sharedPhotos = new List <SharePhoto>();
         foreach (var photo in photos)
         {
             sharedPhotos.Add(SharePhoto.From(UIImage.LoadFromData(NSData.FromArray(photo)), true));
         }
         content.Photos = sharedPhotos.ToArray();
         if (!string.IsNullOrEmpty(hashtag))
         {
             content.Hashtag = new Hashtag()
             {
                 StringRepresentation = hashtag
             }
         }
         ;
         var dialog = new ShareDialog
         {
             Mode = ShareDialogMode.ShareSheet,
             FromViewController = (UIViewController)UIRuntime.NativeRootScreen
         };
         dialog.SetShareContent(content);
         dialog.Show();
     });
 }
        public void ShareImageOnFacebook(string caption, string imagePath)
        {
            SharePhoto tt = SharePhoto.From(new UIImage(imagePath), true);

            tt.Caption = caption;
            SharePhotoContent content = new SharePhotoContent();

            content.Photos = new SharePhoto[] { tt };
            content.SetContentUrl(new NSUrl(imagePath));

            var shareDelegate = new FbDelegate();

            var dialog = new ShareDialog();

            dialog.Mode = ShareDialogMode.FeedBrowser;
            dialog.SetDelegate(shareDelegate);
            dialog.SetShareContent(content);
            dialog.FromViewController = UIApplication.SharedApplication.KeyWindow.RootViewController;

            bool isInstalled = UIApplication.SharedApplication.CanOpenUrl(new NSUrl(urlString: "fb://"));

            if (isInstalled)
            {
                dialog.Mode = ShareDialogMode.Native;
                dialog.Show();
            }
            else
            {
                ShareAPI.Share(content, shareDelegate);
            }
        }
 public static void ShareVideoOnFacebook(string videoUrl, byte[] previewImage = null, string hashtag = null)
 {
     Thread.UI.Post(() =>
     {
         var video = new ShareVideo(new NSCoder())
         {
             PreviewPhoto = SharePhoto.From(UIImage.LoadFromData(NSData.FromArray(previewImage)), true),
             VideoUrl     = NSUrl.FromString(videoUrl)
         };
         var content = new ShareVideoContent {
             Video = video
         };
         if (string.IsNullOrEmpty(hashtag))
         {
             content.Hashtag = new Hashtag()
             {
                 StringRepresentation = hashtag
             }
         }
         ;
         var dialog = new ShareDialog
         {
             Mode = ShareDialogMode.ShareSheet,
             FromViewController = (UIViewController)UIRuntime.NativeRootScreen
         };
         dialog.SetShareContent(content);
         dialog.Show();
     });
 }
Example #8
0
        private static async Task ShareImageAsync(ImageSource image, string message)
        {
            ShareDialog       dialog  = new ShareDialog();
            SharePhotoContent content = new SharePhotoContent();

            var handler = image.GetHandler();

            if (handler == null)
            {
                return;
            }

            var uiImage = await handler.LoadImageAsync(image);

            var items = new List <NSObject> {
                new NSString(message ?? string.Empty)
            };

            items.Add(uiImage);

            var controller = new UIActivityViewController(items.ToArray(), null);

            SharePhoto photo = SharePhoto.From(uiImage, false);

            SharePhoto[] lshare = new SharePhoto[1];
            lshare[0]      = photo;
            content.Photos = lshare;

            dialog.FromViewController = UIApplication.SharedApplication.KeyWindow.RootViewController;
            dialog.Mode = ShareDialogMode.Automatic;
            System.Diagnostics.Debug.WriteLine(dialog.Mode.ToString());
            dialog.SetShareContent(content);
            dialog.Show();
        }
            public static void ShareLinkOnFacebook(string quote, string url)
            {
                var content = new ShareLinkContent.Builder();

                content.SetContentUrl(Android.Net.Uri.Parse(url));
                content.SetQuote(quote);
                ShareDialog.Show(UIRuntime.CurrentActivity, content.Build());
            }
        //Opens share dialog
        private async void share_Click(object sender, RoutedEventArgs e)
        {
            BitmapImage btmap = (BitmapImage)frame.frameImages.getViews()[0];
            StorageFile file  = await StorageFile.GetFileFromApplicationUriAsync(btmap.UriSource);

            var dialog = new ShareDialog(file);
            await dialog.ShowAsync();
        }
            public static void ShareVideoOnFacebook(string videoUrl, byte[] previewImage = null, string hashtag = null)
            {
                var content = new ShareVideoContent.Builder();

                content.SetPreviewPhoto(new SharePhoto.Builder().SetBitmap(BitmapFactory.DecodeByteArray(previewImage, 0, previewImage.Length)).Build());
                content.SetVideo(new ShareVideo.Builder().SetLocalUrl(Android.Net.Uri.Parse(videoUrl)).Build());
                ShareDialog.Show(UIRuntime.CurrentActivity, content.Build());
            }
            public static void SharePhotosOnFacebook(IEnumerable <byte[]> photos, string hashtag = null)
            {
                var content = new SharePhotoContent.Builder().Build();

                foreach (var photo in photos)
                {
                    content.Photos.Add(new SharePhoto.Builder().SetBitmap(BitmapFactory.DecodeByteArray(photo, 0, photo.Length)).Build());
                }
                ShareDialog.Show(UIRuntime.CurrentActivity, content);
            }
Example #13
0
        public async Task SendOpenGraph(object source, ChallengeModel model, string message = null, byte[] data = null, Action <ChallengesFacebookShareResponseType> viewModelResponse = null, ShareTemplateModel shareTemplate = null, ShareResponseModel shareResponse = null)
        {
            ViewModelResponse = viewModelResponse;
            ShareDialog dialog = new ShareDialog(source as Activity);

            dialog.RegisterCallback((source as MainActivity).CallBackManager, this);
            if (shareTemplate == null || shareResponse == null)
            {
                await SL.Manager.RefreshShareTemplate(model.ShareTemplateURL, (response) =>
                {
                    ShareTemplate = response?.ShareTemplate;
                    shareResponse = response;
                });
            }
            else
            {
                ShareTemplate = shareTemplate;
            }

            OpenGraphWasTry = true;
            var openGraphBuilder = new ShareOpenGraphObject.Builder();

            openGraphBuilder.PutString("og:type", "object");
            openGraphBuilder.PutString("og:title", string.IsNullOrEmpty(ShareTemplate?.PostTitle) ? ShareTemplate?.PostHref : ShareTemplate.PostTitle);
            openGraphBuilder.PutString("og:description", string.IsNullOrEmpty(message) ? ShareTemplate?.PostDescription ?? " " : message);
            //openGraphBuilder.PutString("og:url", ShareTemplate?.PostHref ?? model.ShareImage);
            if (model != null && (model.FBShareType == "image" || !string.IsNullOrEmpty(model.ShareImage)))
            {
                openGraphBuilder.PutString("og:image", model.ShareImage);
            }
            if (model != null && (model.FBShareType == "link" || model.FBShareType == null))
            {
                openGraphBuilder.PutString("og:url", ShareTemplate?.PostHref ?? model.ShareImage);
            }
            ShareOpenGraphObject openGraph = openGraphBuilder.Build();
            ShareOpenGraphAction action    = new ShareOpenGraphAction.Builder()
                                             .SetActionType("news.publishes")
                                             .PutObject("object", openGraph)
                                             .JavaCast <ShareOpenGraphAction.Builder>()
                                             .Build();
            ShareOpenGraphContent contentOpenGraph = new ShareOpenGraphContent.Builder()
                                                     .SetPreviewPropertyName("object")
                                                     .SetAction(action)
                                                     .Build();

            dialog.Show(contentOpenGraph, ShareDialog.Mode.Web);
            //ShareDialog.Show(source as Activity, contentOpenGraph);
        }
 public static void ShareLinkOnFacebook(string quote, string url)
 {
     Thread.UI.Post(() =>
     {
         var content = new ShareLinkContent();
         content.SetContentUrl(NSUrl.FromString(url));
         content.Quote = quote;
         var dialog    = new ShareDialog
         {
             Mode = ShareDialogMode.ShareSheet,
             FromViewController = (UIViewController)UIRuntime.NativeRootScreen
         };
         dialog.SetShareContent(content);
         dialog.Show();
     });
 }
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            // Initialize the SDK before executing any other operations
            FacebookSdk.SdkInitialize(Application.Context);

            // create callback manager using CallbackManagerFactory
            callbackManager = CallbackManagerFactory.Create();

            LoginManager.Instance.RegisterCallback(callbackManager, new MyFacebookCallback <LoginResult>(this));

            shareDialog   = new ShareDialog(this);
            shareCallback = new MySharedDialogCallback <SharerResult>(this);
            shareDialog.RegisterCallback(callbackManager, shareCallback);

            if (savedInstanceState != null)
            {
                var name = savedInstanceState.GetString(PENDING_ACTION_BUNDLE_KEY);
                System.Enum.TryParse(name, true, out pendingAction);
            }

            SetContentView(Resource.Layout.main);

            profileTracker = new MyProfileTracker(this);

            profilePictureView = FindViewById <ProfilePictureView>(Resource.Id.profilePicture);
            greeting           = FindViewById <TextView>(Resource.Id.greeting);

            postStatusUpdateButton        = FindViewById <Button>(Resource.Id.postStatusUpdateButton);
            postStatusUpdateButton.Click += (sender, args) =>
            {
                OnClickPostStatusUpdate();
            };

            postPhotoButton        = FindViewById <Button>(Resource.Id.postPhotoButton);
            postPhotoButton.Click += (sender, args) =>
            {
                OnClickPostPhoto();
            };

            // Can we present the share dialog for regular links?
            canPresentShareDialog = ShareDialog.CanShow(Class.FromType(typeof(ShareLinkContent)));

            // Can we present the share dialog for photos?
            canPresentShareDialogWithPhotos = ShareDialog.CanShow(Class.FromType(typeof(SharePhotoContent)));
        }
Example #16
0
        public static async Task ShareFacebook(UIViewController controller, Post post)
        {
            var dialog = new ShareDialog();

            dialog.FromViewController = controller;
            dialog.Mode = ShareDialogMode.Automatic;

            if (post.Links.Any())
            {
                var content = new ShareLinkContent();

                content.SetContentUrl(new NSUrl(post.Links.FirstOrDefault().LinkUrl));
                dialog.SetShareContent(content);
            }
            if (post.Images.Any())
            {
                var content = new SharePhotoContent();
                var path    = await DownloadFileIfNecessary(post.Images.FirstOrDefault().Url);

                content.Photos = new SharePhoto[1] {
                    SharePhoto.From(UIImage.FromFile(path), true)
                };
                dialog.SetShareContent(content);
            }

            if (post.Videos.Any())
            {
                var path = await DownloadFileIfNecessary(post.Videos.FirstOrDefault().Url);

                ALAssetsLibrary library = new ALAssetsLibrary();
                library.WriteVideoToSavedPhotosAlbum(NSUrl.FromFilename(path), (arg1, arg2) =>
                {
                    controller.InvokeOnMainThread(() =>
                    {
                        var content   = new ShareVideoContent();
                        content.Video = ShareVideo.From(arg1.AbsoluteUrl);
                        dialog.SetShareContent(content);
                        dialog.Show();
                    });
                });
            }
            NSError error = new NSError();

            dialog.ValidateWithError(out error);

            var result = dialog.Show();
        }
        private OperationResult ShowSharingSheet(ISharingContent content)
        {
            var dialog = new ShareDialog();

            dialog.FromViewController = NavigationHelper.GetActiveViewController();
            dialog.SetShareContent(content);
            dialog.Mode = ShareDialogMode.ShareSheet;
            bool success = dialog.Show();

            if (success)
            {
                return(OperationResult.AsSuccess());
            }
            else
            {
                return(OperationResult.AsFailure("Could not display Facebook sharing sheet"));
            }
        }
        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            Dialog.Window.RequestFeature(WindowFeatures.NoTitle);

            var view = inflater.Inflate(Resource.Layout.AdicionarComentario, container, true);

            sharedialog = new ShareDialog(this);

            cancelarButton        = view.FindViewById <Button>(Resource.Id.cancelar);
            cancelarButton.Click += Button_Dismiss_Click;

            EditText  comentario    = view.FindViewById <EditText>(Resource.Id.comentario);
            RatingBar classificacao = view.FindViewById <RatingBar>(Resource.Id.classificacao);
            Switch    partilhar     = view.FindViewById <Switch>(Resource.Id.switchpartilhar);

            partilharButton        = view.FindViewById <Button>(Resource.Id.partilhar);
            partilharButton.Click += (sender, e) => {
                Facade.AdicionarClassificacao(comentario.Text, Convert.ToInt32(classificacao.Rating),
                                              DescricaoPrato.pratosel.IdPrato);

                if (partilhar.Checked == true)
                {
                    byte[]     a     = Convert.FromBase64String(DescricaoPrato.pratosel.Fotografia);
                    Bitmap     image = BitmapFactory.DecodeByteArray(a, 0, a.Length);
                    SharePhoto photo = new SharePhoto.Builder()
                                       .SetBitmap(image)
                                       .Build()
                                       .JavaCast <SharePhoto>();

                    SharePhotoContent content = new SharePhotoContent.Builder()
                                                .AddPhoto(photo)
                                                .JavaCast <SharePhotoContent.Builder>()
                                                .Build();
                    sharedialog.Show(content);
                }

                Dismiss();
            };
            return(view);
        }
Example #19
0
        /// <summary>
        /// 分享
        /// </summary>
        /// <param name="video"></param>
        public void Share(Video video)
        {
            ShareDialog dialog = new ShareDialog();

            dialog.WechatClick += (s, a) =>
            {
                ShareHelper.WeChatShare(video.Title, video.ShareUrl);
            };

            dialog.LinkClick += (s, a) =>
            {
                ShareHelper.CopyLink(video.Title);
            };

            dialog.MoreClick += (s, a) =>
            {
                ShareHelper.SystemShare(video.Title, video.ShareUrl);
                //DataTransferManager.ShowShareUI();
            };

            dialog.Show();
        }
Example #20
0
        void RequestSharePhoto(Dictionary <string, object> paramsDictionary)
        {
            if (paramsDictionary != null && paramsDictionary.ContainsKey("photo"))
            {
                UIImage image = null;

                var imageBytes = paramsDictionary["photo"] as byte[];

                if (imageBytes != null)
                {
                    using (var data = NSData.FromArray(imageBytes))
                        image = UIImage.LoadFromData(data);
                }


                SharePhoto photo = Facebook.ShareKit.SharePhoto.From(image, true);

                if (paramsDictionary.ContainsKey("caption"))
                {
                    photo.Caption = $"{paramsDictionary["caption"]}";
                }


                var photoContent = new SharePhotoContent()
                {
                    Photos = new SharePhoto[] { photo }
                };

                //ShareAPI.Share(photoContent, this);
                var window = UIApplication.SharedApplication.KeyWindow;
                var vc     = window.RootViewController;
                while (vc.PresentedViewController != null)
                {
                    vc = vc.PresentedViewController;
                }

                ShareDialog.Show(vc, photoContent, this);
            }
        }
        public void ShareTextOnFacebook(string text)
        {
            ShareLinkContent link = new ShareLinkContent();
            var shareDelegate     = new FbDelegate();

            var dialog = new ShareDialog();

            dialog.Mode = ShareDialogMode.Native;
            dialog.SetDelegate(shareDelegate);
            dialog.SetShareContent(link);
            dialog.FromViewController = UIApplication.SharedApplication.KeyWindow.RootViewController;
            bool isInstalled = UIApplication.SharedApplication.CanOpenUrl(new NSUrl(urlString: "fb://"));

            if (isInstalled)
            {
                dialog.Show();
            }
            else
            {
                new UIAlertView("Error", "Cannot share text when app is not installed", null, "Ok", null).Show();
            }
        }
Example #22
0
        private void shareBtn_Click(object sender, RoutedEventArgs e)
        {
            ShareDialog dialog = new ShareDialog();

            dialog.WechatClick += (s, a) =>
            {
                ViewModel.WeChatShare();
            };

            dialog.LinkClick += (s, a) =>
            {
                ViewModel.CopyLink();
            };

            dialog.MoreClick += (s, a) =>
            {
                dataTransferManager.DataRequested += WebViewPage_DataRequested;
                DataTransferManager.ShowShareUI();
            };

            dialog.Show();
        }
Example #23
0
        public static async Task ShareFacebook(Post post)
        {
            if (post.Images.Any())
            {
                string file = await DownloadFileIfNecessary(post.Images.FirstOrDefault().Url);

                SharePhoto        photo   = new SharePhoto.Builder().SetImageUrl(global::Android.Net.Uri.FromFile(new Java.IO.File(file))).Build() as SharePhoto;
                SharePhotoContent content = new SharePhotoContent.Builder().AddPhoto(photo).Build();
                ShareDialog.Show(CrossCurrentActivity.Current.Activity, content);
            }
            if (post.Links.Any())
            {
                ShareLinkContent content = (new ShareLinkContent.Builder().SetContentUrl(global::Android.Net.Uri.Parse(post.Links.FirstOrDefault().LinkUrl)) as ShareLinkContent.Builder).Build();
                ShareDialog.Show(CrossCurrentActivity.Current.Activity, content);
            }
            if (post.Videos.Any())
            {
                string file = await DownloadFileIfNecessary(post.Videos.FirstOrDefault().Url);

                ShareVideo        video   = new ShareVideo.Builder().SetLocalUrl(global::Android.Net.Uri.FromFile(new Java.IO.File(file))).Build() as ShareVideo;
                ShareVideoContent content = new ShareVideoContent.Builder().SetVideo(video).Build();
                ShareDialog.Show(CrossCurrentActivity.Current.Activity, content);
            }
        }
        void RequestShare(Dictionary <string, object> paramsDictionary)
        {
            if (paramsDictionary.TryGetValue("content", out object shareContent) && shareContent is FacebookShareContent)
            {
                ShareContent content = null;
                if (shareContent is FacebookShareLinkContent)
                {
                    FacebookShareLinkContent linkContent        = shareContent as FacebookShareLinkContent;
                    ShareLinkContent.Builder linkContentBuilder = new ShareLinkContent.Builder();


                    if (linkContent.Quote != null)
                    {
                        linkContentBuilder.SetQuote(linkContent.Quote);
                    }

                    if (linkContent.ContentLink != null)
                    {
                        linkContentBuilder.SetContentUrl(Android.Net.Uri.Parse(linkContent.ContentLink.AbsoluteUri));
                    }

                    if (!string.IsNullOrEmpty(linkContent.Hashtag))
                    {
                        var shareHashTagBuilder = new ShareHashtag.Builder();
                        shareHashTagBuilder.SetHashtag(linkContent.Hashtag);
                        linkContentBuilder.SetShareHashtag(shareHashTagBuilder.Build().JavaCast <ShareHashtag>());
                    }

                    if (linkContent.PeopleIds != null && linkContent.PeopleIds.Length > 0)
                    {
                        linkContentBuilder.SetPeopleIds(linkContent.PeopleIds);
                    }

                    if (!string.IsNullOrEmpty(linkContent.PlaceId))
                    {
                        linkContentBuilder.SetPlaceId(linkContent.PlaceId);
                    }

                    if (!string.IsNullOrEmpty(linkContent.Ref))
                    {
                        linkContentBuilder.SetRef(linkContent.Ref);
                    }

                    content = linkContentBuilder.Build();
                }
                else if (shareContent is FacebookSharePhotoContent)
                {
                    FacebookSharePhotoContent photoContent = shareContent as FacebookSharePhotoContent;

                    SharePhotoContent.Builder photoContentBuilder = new SharePhotoContent.Builder();

                    if (photoContent.Photos != null && photoContent.Photos.Length > 0)
                    {
                        foreach (var p in photoContent.Photos)
                        {
                            SharePhoto.Builder photoBuilder = new SharePhoto.Builder();

                            if (!string.IsNullOrEmpty(p.Caption))
                            {
                                photoBuilder.SetCaption(p.Caption);
                            }

                            if (p.ImageUrl != null && !string.IsNullOrEmpty(p.ImageUrl.AbsoluteUri))
                            {
                                photoBuilder.SetImageUrl(Android.Net.Uri.Parse(p.ImageUrl.AbsoluteUri));
                            }

                            if (p.Image != null)
                            {
                                Bitmap bmp = BitmapFactory.DecodeByteArray(p.Image, 0, p.Image.Length);

                                photoBuilder.SetBitmap(bmp);
                            }
                            photoContentBuilder.AddPhoto(photoBuilder.Build().JavaCast <SharePhoto>());
                        }
                    }

                    if (photoContent.ContentLink != null)
                    {
                        photoContentBuilder.SetContentUrl(Android.Net.Uri.Parse(photoContent.ContentLink.AbsoluteUri));
                    }

                    if (!string.IsNullOrEmpty(photoContent.Hashtag))
                    {
                        var shareHashTagBuilder = new ShareHashtag.Builder();
                        shareHashTagBuilder.SetHashtag(photoContent.Hashtag);
                        photoContentBuilder.SetShareHashtag(shareHashTagBuilder.Build().JavaCast <ShareHashtag>());
                    }

                    if (photoContent.PeopleIds != null && photoContent.PeopleIds.Length > 0)
                    {
                        photoContentBuilder.SetPeopleIds(photoContent.PeopleIds);
                    }

                    if (!string.IsNullOrEmpty(photoContent.PlaceId))
                    {
                        photoContentBuilder.SetPlaceId(photoContent.PlaceId);
                    }

                    if (!string.IsNullOrEmpty(photoContent.Ref))
                    {
                        photoContentBuilder.SetRef(photoContent.Ref);
                    }

                    content = photoContentBuilder.Build();
                }
                else if (shareContent is FacebookShareVideoContent)
                {
                    FacebookShareVideoContent videoContent        = shareContent as FacebookShareVideoContent;
                    ShareVideoContent.Builder videoContentBuilder = new ShareVideoContent.Builder();


                    /*if (videoContent.PreviewPhoto != null)
                     * {
                     *   SharePhoto.Builder photoBuilder = new SharePhoto.Builder();
                     *
                     *   if (!string.IsNullOrEmpty(videoContent.PreviewPhoto.Caption))
                     *   {
                     *       photoBuilder.SetCaption(videoContent.PreviewPhoto.Caption);
                     *   }
                     *
                     *   if (videoContent.PreviewPhoto.ImageUrl != null && !string.IsNullOrEmpty(videoContent.PreviewPhoto.ImageUrl.AbsoluteUri))
                     *   {
                     *       photoBuilder.SetImageUrl(Android.Net.Uri.Parse(videoContent.PreviewPhoto.ImageUrl.AbsoluteUri));
                     *   }
                     *
                     *   if (videoContent.PreviewPhoto.Image != null)
                     *   {
                     *       Bitmap bmp = BitmapFactory.DecodeByteArray(videoContent.PreviewPhoto.Image, 0, videoContent.PreviewPhoto.Image.Length);
                     *
                     *       photoBuilder.SetBitmap(bmp);
                     *   }
                     *   videoContentBuilder.SetPreviewPhoto(photoBuilder.Build().JavaCast<SharePhoto>());
                     * }*/

                    if (videoContent.Video != null)
                    {
                        ShareVideo.Builder videoBuilder = new ShareVideo.Builder();

                        if (videoContent.Video.LocalUrl != null)
                        {
                            videoBuilder.SetLocalUrl(Android.Net.Uri.Parse(videoContent.Video.LocalUrl.AbsoluteUri));
                        }

                        videoContentBuilder.SetVideo(videoBuilder.Build().JavaCast <ShareVideo>());
                    }


                    if (videoContent.ContentLink != null)
                    {
                        videoContentBuilder.SetContentUrl(Android.Net.Uri.Parse(videoContent.ContentLink.AbsoluteUri));
                    }

                    if (!string.IsNullOrEmpty(videoContent.Hashtag))
                    {
                        var shareHashTagBuilder = new ShareHashtag.Builder();
                        shareHashTagBuilder.SetHashtag(videoContent.Hashtag);
                        videoContentBuilder.SetShareHashtag(shareHashTagBuilder.Build().JavaCast <ShareHashtag>());
                    }

                    if (videoContent.PeopleIds != null && videoContent.PeopleIds.Length > 0)
                    {
                        videoContentBuilder.SetPeopleIds(videoContent.PeopleIds);
                    }

                    if (!string.IsNullOrEmpty(videoContent.PlaceId))
                    {
                        videoContentBuilder.SetPlaceId(videoContent.PlaceId);
                    }

                    if (!string.IsNullOrEmpty(videoContent.Ref))
                    {
                        videoContentBuilder.SetRef(videoContent.Ref);
                    }

                    content = videoContentBuilder.Build();
                }

                if (content != null)
                {
                    //ShareApi.Share(content, shareCallback);
                    ShareDialog dialog = new ShareDialog(CurrentActivity);
                    dialog.RegisterCallback(mCallbackManager, shareCallback);
                    dialog.ShouldFailOnDataError = true;
                    dialog.Show(content, ShareDialog.Mode.Automatic);
                }
            }
        }
Example #25
0
        public async Task ShareFacebookChallenge(object source, ChallengeModel model, string message = null, byte[] data = null, Action <ChallengesFacebookShareResponseType> viewModelResponse = null)
        {
            OpenGraphWasTry   = false;
            ViewModelResponse = viewModelResponse;
            Activity          = source as Activity;
            Model             = model;
            ShareTemplateModel shareTemplate = null;
            ShareResponseModel shareResponse = null;
            await SL.Manager.RefreshShareTemplate(Model.ShareTemplateURL, (response) =>
            {
                shareTemplate = response?.ShareTemplate;
                shareResponse = response;
            });

            try
            {
                ShareDialog dialog = new ShareDialog(Activity);
                dialog.RegisterCallback((Activity as MainActivity).CallBackManager, this);
                if (string.IsNullOrEmpty(message) && Model.FBShareType == "image")
                {
                    if (data == null && !string.IsNullOrEmpty(Model.Image))
                    {
                        data = await ImageUrlToByteArrayLocalConverter.ReadImageUrlToBytesArray(Model.Image);
                    }
                    if (data == null)
                    {
                        return;
                    }
                    var bitmapImage = await BitmapFactory.DecodeByteArrayAsync(data, 0, data.Length);

                    var photoBuilder = new SharePhoto.Builder();
                    photoBuilder.SetUserGenerated(true);
                    var sharePhoto            = photoBuilder.SetBitmap(bitmapImage);
                    SharePhotoContent content = new SharePhotoContent.Builder().AddPhoto(sharePhoto.Build()).Build();
                    if (dialog.CanShow(content, ShareDialog.Mode.Web))
                    {
                        dialog.Show(content, ShareDialog.Mode.Web);
                        return;
                    }
                }
                if (string.IsNullOrEmpty(message) && (Model.FBShareType == null || Model.FBShareType == "link"))
                {
                    var uri = Android.Net.Uri.Parse(shareTemplate?.PostHref ?? Model.ShareImage);

                    var linkBuilder = new ShareLinkContent.Builder();
                    linkBuilder.SetContentUrl(Android.Net.Uri.Parse(shareTemplate?.PostHref ?? Model.ShareImage));
                    ShareLinkContent content = linkBuilder.Build();

                    if (dialog.CanShow(content, ShareDialog.Mode.Web))
                    {
                        dialog.Show(content, ShareDialog.Mode.Web);
                        return;
                    }
                }

                ViewModelResponse(ChallengesFacebookShareResponseType.NativeUninstallApp);
            }
            catch (System.Exception ex)
            {
                await SendOpenGraph(Activity, Model, message, null, null, shareTemplate, shareResponse);
            }
            return;
        }
        public async void SendOpenGraph(object source, ChallengeModel model, string message = null)
        {
            ShareTemplateModel shareTemplate = null;
            ShareResponseModel shareResponse = null;

            await SL.Manager.RefreshShareTemplate(model.ShareTemplateURL, (response) =>
            {
                shareTemplate = response?.ShareTemplate;
                shareResponse = response;
            });

            NSUrl url = new NSUrl(shareTemplate?.PostHref ?? model.ShareImage);

            if (string.IsNullOrEmpty(url?.AbsoluteString))
            {
                new UIAlertView("Sharing Error", string.IsNullOrEmpty(shareResponse?.ResponseMessage) ? "Sorry. No url come from server" : shareResponse.ResponseMessage, source as IUIAlertViewDelegate, "Ok").Show();
                return;
            }

            ShareDialog dialog = new ShareDialog();

            dialog.SetShouldFailOnDataError(true);
            dialog.FromViewController = source as UIViewController;
            dialog.SetDelegate(source as ISharingDelegate ?? new FBSharingDelegate());

            NSString[] keys;
            NSObject[] objects;

            string imgUrl = null;

            try
            {
                if (!string.IsNullOrEmpty(model.ShareImage))
                {
                    await ImageService.Instance.LoadUrl(model.ShareImage).IntoAsync(new UIImageView());

                    imgUrl = model.ShareImage;
                }
            }
            catch (Exception) { }

            if (string.IsNullOrEmpty(imgUrl))
            {
                keys = new NSString[] {
                    new NSString("og:type"),
                    new NSString("og:url"),
                    new NSString("og:title"),
                    new NSString("og:description"),
                };
                objects = new NSObject[] {
                    NSObject.FromObject("article"),
                    NSObject.FromObject(url),
                    NSObject.FromObject(string.IsNullOrEmpty(shareTemplate?.PostTitle) ? url.AbsoluteString : shareTemplate.PostTitle),
                    NSObject.FromObject(string.IsNullOrEmpty(message) ? shareTemplate?.PostDescription ?? " " : message),
                };
            }
            else
            {
                keys = new NSString[] {
                    new NSString("og:type"),
                    new NSString("og:url"),
                    new NSString("og:title"),
                    new NSString("og:description"),
                    new NSString("og:image"),
                };
                objects = new NSObject[]
                {
                    NSObject.FromObject("article"),
                    NSObject.FromObject(url),
                    NSObject.FromObject(string.IsNullOrEmpty(shareTemplate?.PostTitle) ? url.AbsoluteString : shareTemplate.PostTitle),
                    NSObject.FromObject(string.IsNullOrEmpty(message) ? shareTemplate?.PostDescription ?? " " : message),
                    NSObject.FromObject(imgUrl),
                };
            }

            var propesties       = new NSDictionary <NSString, NSObject>(keys, objects);
            var openGraph        = ShareOpenGraphObject.ObjectWithProperties(propesties);
            var action           = ShareOpenGraphAction.Action("news.publishes", openGraph, "article");
            var contentOpenGraph = new ShareOpenGraphContent
            {
                Action = action,
                PreviewPropertyName = "article"
            };

            dialog.SetShareContent(contentOpenGraph);
            dialog.Mode = ShareDialogMode.Web;

            dialog.Show();

            if (dialog.Mode == ShareDialogMode.Web)
            {
                StylishFbWebDialog();
            }
        }
        public async void ShareFacebookChallenge(object source, ChallengeModel model, string message = null)
        {
            ShareTemplateModel shareTemplate = null;
            ShareResponseModel shareResponse = null;
            await SL.Manager.RefreshShareTemplate(model.ShareTemplateURL, (response) =>
            {
                shareTemplate = response?.ShareTemplate;
                shareResponse = response;
            });

            NSUrl url = new NSUrl(shareTemplate?.PostHref ?? model.ShareImage);

            ShareDialog dialog = new ShareDialog();

            dialog.SetShouldFailOnDataError(true);
            dialog.FromViewController = source as UIViewController;
            dialog.SetDelegate(source as ISharingDelegate ?? new FBSharingDelegate());

            if (string.IsNullOrEmpty(message) && model.FBShareType == "image")
            {
                UIImageView imageView = new UIImageView();
                try
                {
                    await ImageService.Instance.LoadUrl(model.ShareImage).IntoAsync(imageView);
                }
                catch (Exception)
                {
                    try
                    {
                        await ImageService.Instance.LoadUrl(model.Image).IntoAsync(imageView);
                    }
                    catch (Exception)
                    {
                    }
                }

                dialog.SetShareContent(new SharePhotoContent()
                {
                    Photos = new SharePhoto[] { SharePhoto.From(imageView.Image, true) }
                });
                dialog.Mode = ShareDialogMode.Native;
            }
            else if (string.IsNullOrEmpty(message) && (model.FBShareType == "link" || model.FBShareType == null))
            {
                ShareLinkContent contentLink = new ShareLinkContent();
                if (string.IsNullOrEmpty(url?.AbsoluteString))
                {
                    new UIAlertView("Sharing Error", string.IsNullOrEmpty(shareResponse?.ResponseMessage) ? "Sorry. No url come from server" : shareResponse.ResponseMessage, source as IUIAlertViewDelegate, "Ok").Show();
                    return;
                }
                contentLink.SetContentUrl(url);

                dialog.SetShareContent(contentLink);
                dialog.Mode = ShareDialogMode.Web;
            }
            else
            {
                SendOpenGraph(source, model, message);
                return;
            }

            if (!dialog.CanShow())
            {
                SendOpenGraph(source, model, message);
                return;
            }
            dialog.Show();

            if (dialog.Mode == ShareDialogMode.Web)
            {
                StylishFbWebDialog();
            }
        }
Example #28
0
        public void ShowPostToFacebook()
        {
            ShareDialog sharedialog = new ShareDialog (this);
            sharedialog.RegisterCallback (this.facebookcallbackmanager,new FaceBookShareResult(this));
            if (ShareDialog.CanShow(Java.Lang.Class.FromType(typeof(ShareOpenGraphContent)))) {
             				var builder = new ShareLinkContent.Builder ();
                var opengraphcontent = new ShareOpenGraphContent.Builder ();
                if (this.eventcard.eventinfo.representative_needed.Equals ("N")) {
                    builder.SetContentUrl (global::Android.Net.Uri.Parse (this.eventcard.eventinfo.sell_ticket_url));
                    string message = String.Format (RaffleDetailDate.c_facebookMessageTemplate_WithLink, this.eventcard.eventinfo.organization, this.eventcard.eventinfo.location_name);
                    builder.SetContentDescription (message);

                } else {
                    builder.SetContentUrl (global::Android.Net.Uri.Parse (RaffleDetailDate.Tap5050WebPageLink));
                    string message = string.Format(RaffleDetailDate.c_facebookMessageTemplate_NoLink, this.eventcard.eventinfo.organization);
                    builder.SetContentDescription (message);
                }
                if(!string.IsNullOrEmpty(this.eventcard.eventinfo.event_name)){
                    builder.SetContentTitle(this.eventcard.eventinfo.event_name);
                }
                string url = "https://tap5050.com/apex/wwv_flow_file_mgr.get_file?p_security_group_id=9113403474056812&p_fname=tap5050logo.png";
                if(!string.IsNullOrEmpty(this.eventcard.eventinfo.image_url)){
                    url = this.eventcard.eventinfo.image_url;
                }
                //builder.SetImageUrl (global::Android.Net.Uri.FromFile(TapUtil.bitmapToFile(this.eventcard.imagemap)));
                builder.SetImageUrl(global::Android.Net.Uri.Parse(url));
                ShareLinkContent content = builder.Build ();
                sharedialog.Show (content);
            }
        }
Example #29
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            FacebookSdk.SdkInitialize(this.ApplicationContext);

            callbackManager = CallbackManagerFactory.Create();

            var loginCallback = new FacebookCallback <LoginResult> {
                HandleSuccess = loginResult => {
                    HandlePendingAction();
                    UpdateUI();
                },
                HandleCancel = () => {
                    if (pendingAction != PendingAction.NONE)
                    {
                        ShowAlert(
                            GetString(Resource.String.cancelled),
                            GetString(Resource.String.permission_not_granted));
                        pendingAction = PendingAction.NONE;
                    }
                    UpdateUI();
                },
                HandleError = loginError => {
                    if (pendingAction != PendingAction.NONE &&
                        loginError is FacebookAuthorizationException)
                    {
                        ShowAlert(
                            GetString(Resource.String.cancelled),
                            GetString(Resource.String.permission_not_granted));
                        pendingAction = PendingAction.NONE;
                    }
                    UpdateUI();
                }
            };

            LoginManager.Instance.RegisterCallback(callbackManager, loginCallback);

            shareCallback = new FacebookCallback <SharerResult> {
                HandleSuccess = shareResult => {
                    Console.WriteLine("HelloFacebook: Success!");

                    if (shareResult.PostId != null)
                    {
                        var title    = Parent.GetString(Resource.String.error);
                        var id       = shareResult.PostId;
                        var alertMsg = Parent.GetString(Resource.String.successfully_posted_post, id);

                        ShowAlert(title, alertMsg);
                    }
                },
                HandleCancel = () => {
                    Console.WriteLine("HelloFacebook: Canceled");
                },
                HandleError = shareError => {
                    Console.WriteLine("HelloFacebook: Error: {0}", shareError);

                    var title    = Parent.GetString(Resource.String.error);
                    var alertMsg = shareError.Message;

                    ShowAlert(title, alertMsg);
                }
            };

            shareDialog = new ShareDialog(this);
            shareDialog.RegisterCallback(callbackManager, shareCallback);

            if (savedInstanceState != null)
            {
                var name = savedInstanceState.GetString(PENDING_ACTION_BUNDLE_KEY);
                pendingAction = (PendingAction)Enum.Parse(typeof(PendingAction), name);
            }

            SetContentView(Resource.Layout.main);

            profileTracker = new CustomProfileTracker {
                HandleCurrentProfileChanged = (oldProfile, currentProfile) => {
                    UpdateUI();
                    HandlePendingAction();
                }
            };

            profilePictureView = FindViewById <ProfilePictureView> (Resource.Id.profilePicture);

            greeting = FindViewById <TextView> (Resource.Id.greeting);

            postStatusUpdateButton        = FindViewById <Button> (Resource.Id.postStatusUpdateButton);
            postStatusUpdateButton.Click += (sender, e) => {
                PerformPublish(PendingAction.POST_STATUS_UPDATE, canPresentShareDialog);
            };

            postPhotoButton        = FindViewById <Button> (Resource.Id.postPhotoButton);
            postPhotoButton.Click += (sender, e) => {
                PerformPublish(PendingAction.POST_PHOTO, canPresentShareDialogWithPhotos);
            };

            // Can we present the share dialog for regular links?
            canPresentShareDialog = ShareDialog.CanShow(Java.Lang.Class.FromType(typeof(ShareLinkContent)));

            // Can we present the share dialog for photos?
            canPresentShareDialogWithPhotos = ShareDialog.CanShow(Java.Lang.Class.FromType(typeof(SharePhotoContent)));
        }
Example #30
0
        void RequestShare(Dictionary <string, object> paramsDictionary)
        {
            if (paramsDictionary.TryGetValue("content", out object shareContent) && shareContent is FacebookShareContent)
            {
                ISharingContent content = null;
                if (shareContent is FacebookShareLinkContent)
                {
                    FacebookShareLinkContent linkContent  = shareContent as FacebookShareLinkContent;
                    ShareLinkContent         sLinkContent = new ShareLinkContent();


                    if (linkContent.Quote != null)
                    {
                        sLinkContent.Quote = linkContent.Quote;
                    }

                    if (linkContent.ContentLink != null)
                    {
                        sLinkContent.SetContentUrl(linkContent.ContentLink);
                    }

                    if (!string.IsNullOrEmpty(linkContent.Hashtag))
                    {
                        var shareHashTag = new Hashtag();
                        shareHashTag.StringRepresentation = linkContent.Hashtag;
                        sLinkContent.Hashtag = shareHashTag;
                    }

                    if (linkContent.PeopleIds != null && linkContent.PeopleIds.Length > 0)
                    {
                        sLinkContent.SetPeopleIds(linkContent.PeopleIds);
                    }

                    if (!string.IsNullOrEmpty(linkContent.PlaceId))
                    {
                        sLinkContent.SetPlaceId(linkContent.PlaceId);
                    }

                    if (!string.IsNullOrEmpty(linkContent.Ref))
                    {
                        sLinkContent.SetRef(linkContent.Ref);
                    }

                    content = sLinkContent;
                }
                else if (shareContent is FacebookSharePhotoContent)
                {
                    FacebookSharePhotoContent photoContent = shareContent as FacebookSharePhotoContent;

                    SharePhotoContent sharePhotoContent = new SharePhotoContent();

                    if (photoContent.Photos != null && photoContent.Photos.Length > 0)
                    {
                        List <SharePhoto> photos = new List <SharePhoto>();
                        foreach (var p in photoContent.Photos)
                        {
                            if (p.ImageUrl != null && !string.IsNullOrEmpty(p.ImageUrl.AbsoluteUri))
                            {
                                SharePhoto photoFromUrl = SharePhoto.From(p.ImageUrl, true);

                                if (!string.IsNullOrEmpty(p.Caption))
                                {
                                    photoFromUrl.Caption = p.Caption;
                                }

                                photos.Add(photoFromUrl);
                            }

                            if (p.Image != null)
                            {
                                UIImage image = null;

                                var imageBytes = p.Image as byte[];

                                if (imageBytes != null)
                                {
                                    using (var data = NSData.FromArray(imageBytes))
                                        image = UIImage.LoadFromData(data);

                                    SharePhoto sPhoto = Facebook.ShareKit.SharePhoto.From(image, true);

                                    if (!string.IsNullOrEmpty(p.Caption))
                                    {
                                        sPhoto.Caption = p.Caption;
                                    }


                                    photos.Add(sPhoto);
                                }
                            }
                        }

                        if (photos.Count > 0)
                        {
                            sharePhotoContent.Photos = photos.ToArray();
                        }
                    }

                    if (photoContent.ContentLink != null)
                    {
                        sharePhotoContent.SetContentUrl(photoContent.ContentLink);
                    }

                    if (!string.IsNullOrEmpty(photoContent.Hashtag))
                    {
                        var shareHashTag = new Hashtag();
                        shareHashTag.StringRepresentation = photoContent.Hashtag;
                        sharePhotoContent.Hashtag         = (shareHashTag);
                    }

                    if (photoContent.PeopleIds != null && photoContent.PeopleIds.Length > 0)
                    {
                        sharePhotoContent.SetPeopleIds(photoContent.PeopleIds);
                    }

                    if (!string.IsNullOrEmpty(photoContent.PlaceId))
                    {
                        sharePhotoContent.SetPlaceId(photoContent.PlaceId);
                    }

                    if (!string.IsNullOrEmpty(photoContent.Ref))
                    {
                        sharePhotoContent.SetRef(photoContent.Ref);
                    }

                    content = sharePhotoContent;
                }
                else if (shareContent is FacebookShareVideoContent)
                {
                    FacebookShareVideoContent videoContent      = shareContent as FacebookShareVideoContent;
                    ShareVideoContent         shareVideoContent = new ShareVideoContent();


                    if (videoContent.PreviewPhoto != null)
                    {
                        if (videoContent.PreviewPhoto.ImageUrl != null && !string.IsNullOrEmpty(videoContent.PreviewPhoto.ImageUrl.AbsoluteUri))
                        {
                            SharePhoto photoFromUrl = Facebook.ShareKit.SharePhoto.From(videoContent.PreviewPhoto.ImageUrl, true);

                            if (!string.IsNullOrEmpty(videoContent.PreviewPhoto.Caption))
                            {
                                photoFromUrl.Caption = videoContent.PreviewPhoto.Caption;
                            }

                            shareVideoContent.PreviewPhoto = photoFromUrl;
                        }

                        if (videoContent.PreviewPhoto.Image != null)
                        {
                            UIImage image = null;

                            var imageBytes = videoContent.PreviewPhoto.Image as byte[];

                            if (imageBytes != null)
                            {
                                using (var data = NSData.FromArray(imageBytes))
                                    image = UIImage.LoadFromData(data);

                                SharePhoto photo = Facebook.ShareKit.SharePhoto.From(image, true);

                                if (!string.IsNullOrEmpty(videoContent.PreviewPhoto.Caption))
                                {
                                    photo.Caption = videoContent.PreviewPhoto.Caption;
                                }


                                shareVideoContent.PreviewPhoto = photo;
                            }
                        }
                    }

                    if (videoContent.Video != null)
                    {
                        if (videoContent.Video.LocalUrl != null)
                        {
                            shareVideoContent.Video = ShareVideo.From(videoContent.Video.LocalUrl);
                        }
                    }

                    if (videoContent.ContentLink != null)
                    {
                        shareVideoContent.SetContentUrl(videoContent.ContentLink);
                    }

                    if (!string.IsNullOrEmpty(videoContent.Hashtag))
                    {
                        var shareHashTag = new Hashtag();
                        shareHashTag.StringRepresentation = videoContent.Hashtag;
                        shareVideoContent.Hashtag         = (shareHashTag);
                    }

                    if (videoContent.PeopleIds != null && videoContent.PeopleIds.Length > 0)
                    {
                        shareVideoContent.SetPeopleIds(videoContent.PeopleIds);
                    }

                    if (!string.IsNullOrEmpty(videoContent.PlaceId))
                    {
                        shareVideoContent.SetPlaceId(videoContent.PlaceId);
                    }

                    if (!string.IsNullOrEmpty(videoContent.Ref))
                    {
                        shareVideoContent.SetRef(videoContent.Ref);
                    }

                    content = shareVideoContent;
                }

                if (content != null)
                {
                    //ShareAPI.Share(content, this);

                    var window = UIApplication.SharedApplication.KeyWindow;
                    var vc     = window.RootViewController;
                    while (vc.PresentedViewController != null)
                    {
                        vc = vc.PresentedViewController;
                    }

                    ShareDialog.Show(vc, content, this);
                }
            }
        }
        protected override void OnCreate(Android.OS.Bundle savedInstanceState)
        {
            string title          = Intent.GetStringExtra("Title");
            string description    = Intent.GetStringExtra("Description");
            string imageUrl       = Intent.GetStringExtra("ImageUrl");
            string localImagePath = Intent.GetStringExtra("ImagePath");
            string localVideoPath = Intent.GetStringExtra("VideoPath");
            string link           = Intent.GetStringExtra("Link");

            base.OnCreate(savedInstanceState);

            FacebookSdk.ApplicationId   = Droid.DS.FacebookLogin.FacebookAppId;
            FacebookSdk.ApplicationName = "";
            FacebookSdk.SdkInitialize(ApplicationContext);


            callbackManager = CallbackManagerFactory.Create();
            fbShareCallback = new FacebookCallback <SharerResult>
            {
                HandleSuccess = loginResult =>
                {
                    Toast.MakeText(ApplicationContext, "Your post has been shared successfully.", ToastLength.Long).Show();
                    ShareCompleted(ShareStatus.Success, "Your post has been shared successfully.");
                },
                HandleCancel = () =>
                {
                    Toast.MakeText(ApplicationContext, "Cancelled", ToastLength.Long).Show();
                    ShareCompleted(ShareStatus.Cancelled, "User has cancelled.");
                },
                HandleError = loginError =>
                {
                    Toast.MakeText(ApplicationContext, "Error " + loginError.Message, ToastLength.Long).Show();
                    ShareCompleted(ShareStatus.Error, loginError.Message);
                }
            };
            ShareContent shareContent = null;

            if (!string.IsNullOrWhiteSpace(localImagePath))
            {
                SharePhoto sharePhoto = (SharePhoto) new SharePhoto.Builder()
                                        .SetBitmap(Android.Graphics.BitmapFactory.DecodeFile(localImagePath))
                                        .SetCaption(title)
                                        .Build();
                SharePhotoContent content = new SharePhotoContent.Builder()
                                            .AddPhoto(sharePhoto)
                                            .Build();

                shareContent = content; // new ShareMediaContent.Builder().AddMedium(sharePhoto).Build();
            }

            else if (!string.IsNullOrWhiteSpace(localVideoPath))
            {
                Android.Net.Uri videoFileUri = Android.Net.Uri.FromFile(new Java.IO.File(localVideoPath));
                ShareVideo      shareVideo   = (ShareVideo) new ShareVideo.Builder()
                                               .SetLocalUrl(videoFileUri)
                                               .Build();
                ShareVideoContent content = new ShareVideoContent.Builder()
                                            .SetVideo(shareVideo)
                                            .Build();
                shareContent = content;
            }
            else
            {
                var contentBuilder = new ShareLinkContent.Builder();
                contentBuilder.SetContentTitle(title);
                if (!string.IsNullOrWhiteSpace(description))
                {
                    contentBuilder.SetContentDescription(description);
                }
                if (!string.IsNullOrWhiteSpace(imageUrl))
                {
                    contentBuilder.SetImageUrl(Android.Net.Uri.Parse(imageUrl));
                }
                if (!string.IsNullOrWhiteSpace(link))
                {
                    contentBuilder.SetContentUrl(Android.Net.Uri.Parse(link));
                }
                shareContent = contentBuilder.Build();
            }
            if (ShareDialog.CanShow(shareContent.Class))
            {
                var shareDialog = new ShareDialog(this);
                shareDialog.RegisterCallback(callbackManager, fbShareCallback);
                shareDialog.Show(shareContent, ShareDialog.Mode.Automatic);
                return;
            }
            else
            {
                var FBLoginCallback = new FacebookCallback <LoginResult>
                {
                    HandleSuccess = loginResult =>
                    {
                        ShareApi.Share(shareContent, fbShareCallback);
                    },
                    HandleCancel = () =>
                    {
                        Toast.MakeText(ApplicationContext, "Cancelled", ToastLength.Long).Show();
                        ShareCompleted(ShareStatus.Cancelled, "User has cancelled.");
                    },
                    HandleError = loginError =>
                    {
                        LoginManager.Instance.LogOut();
                        Toast.MakeText(ApplicationContext, "Error " + loginError.Message, ToastLength.Long).Show();
                        ShareCompleted(ShareStatus.Error, loginError.Message);
                    }
                };
                LoginManager.Instance.RegisterCallback(callbackManager, FBLoginCallback);
                LoginManager.Instance.LogInWithPublishPermissions(this, new System.Collections.Generic.List <string>()
                {
                    "publish_actions"
                });
            }
        }