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); } }
async 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); } }
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 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(); }); }
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); } }
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 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(); }); }
private void PostPhoto() { Bitmap image = BitmapFactory.DecodeResource(Resources, Resource.Drawable.icon); SharePhoto sharePhoto = (SharePhoto) new SharePhoto.Builder().SetBitmap(image).Build(); IList <SharePhoto> photos = new List <SharePhoto>(); photos.Add(sharePhoto); SharePhotoContent sharePhotoContent = new SharePhotoContent.Builder().SetPhotos(photos).Build(); if (canPresentShareDialogWithPhotos) { shareDialog.Show(sharePhotoContent); } else if (HasPublishPermission()) { ShareApi.Share(sharePhotoContent, shareCallback); } else { pendingAction = PendingAction.POST_PHOTO; // We need to get new permissions, then complete the action when we get called back. LoginManager.Instance.LogInWithPublishPermissions(this, PERMISSION); } }
private void OnImagePickerFinishedPickingMedia(object sender, UIImagePickerMediaPickedEventArgs e) { UIImage image = e.EditedImage ?? e.OriginalImage; if (image != null) { NSData data; if (e.ReferenceUrl.PathExtension.ToUpper().Equals("PNG")) { data = image.AsPNG(); } else { data = image.AsJPEG(1); } SharePhoto sharedPhoto = new SharePhoto { ImageName = e.ReferenceUrl.ToString(), ImageData = data.AsStream() }; UnregisterEventHandlers(); taskCompletionSource.SetResult(sharedPhoto); } else { UnregisterEventHandlers(); taskCompletionSource.SetResult(null); } imagePicker.DismissModalViewController(true); }
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(); }
public OperationResult ShareImageFiles(List <string> assetPaths, List <string> hashtags = null) { List <SharePhoto> sharePhotos = new List <SharePhoto>(); foreach (var path in assetPaths) { var url = new NSUrl(path); sharePhotos.Add(SharePhoto.From(url, true)); } var content = new SharePhotoContent(); content.Photos = sharePhotos.ToArray(); AddTagsToContent(content, hashtags); return(ShowSharingSheet(content)); }
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); } }
protected override void OnActivityResult(int requestCode, Result resultCode, Intent data) { base.OnActivityResult(requestCode, resultCode, data); if (requestCode == PickImageId) { if ((resultCode == Result.Ok) && (data != null)) { SharePhoto sharedPhoto = new SharePhoto { ImageName = data.Data.ToString(), ImageData = ContentResolver.OpenInputStream(data.Data) }; PickImageTaskCompletionSource.SetResult(sharedPhoto); } else { PickImageTaskCompletionSource.SetResult(null); } } }
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(); } }
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.SetHashtag(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.SetHashtag(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); } } }
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" }); } }