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()); }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); FacebookSdk.SdkInitialize(this.ApplicationContext); // Set our view from the "main" layout resource mProfileTracker = new MyProfileTracker(); mProfileTracker.mOnProfileChanged += MProfileTracker_mOnProfileChanged; mProfileTracker.StartTracking(); SetContentView(Resource.Layout.Main); Button faceBookButton = FindViewById <Button>(Resource.Id.button); mTxtFirstName = FindViewById <TextView>(Resource.Id.txtFirstName); mTxtLastName = FindViewById <TextView>(Resource.Id.txtLastName); mTxtName = FindViewById <TextView>(Resource.Id.txtName); mProfilePic = FindViewById <ProfilePictureView>(Resource.Id.profilePic); mBtnShared = FindViewById <ShareButton>(Resource.Id.btnShare); mBtnGetEmail = FindViewById <Button>(Resource.Id.btnGetEmail); LoginButton button = FindViewById <LoginButton>(Resource.Id.login_button); button.SetReadPermissions(new List <string> { "public_profile", "user_friends", "email" }); mCallBackManager = CallbackManagerFactory.Create(); button.RegisterCallback(mCallBackManager, this); mBtnGetEmail.Click += (o, e) => { GraphRequest request = GraphRequest.NewMeRequest(AccessToken.CurrentAccessToken, this); Bundle parameters = new Bundle(); parameters.PutString("fields", "id,name,age_range,email"); request.Parameters = parameters; request.ExecuteAsync(); }; ShareLinkContent content = new ShareLinkContent.Builder().Build(); mBtnShared.ShareContent = content; }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.endgame_activity); string winnerText = Intent.GetStringExtra(StringConstants.END_MESSAGE); figure = (Figures)Intent.GetIntExtra(StringConstants.FIGURE, (int)Figures.X); buttonRestart = FindViewById <Button>(Resource.Id.RestartButton); textViewWinnerName = FindViewById <TextView>(Resource.Id.TextViewWinnerName); shareButton = FindViewById <ShareButton>(Resource.Id.fb_share_button); textViewWinnerName.Text = winnerText; //Share content to FB ShareLinkContent.Builder builder = new ShareLinkContent.Builder(); builder.SetContentUrl(Android.Net.Uri.Parse("DI.FM")); ShareContent content = builder.Build(); shareButton.ShareContent = content; }
private void PostStatusUpdate() { var profile = Profile.CurrentProfile; ShareLinkContent linkContent = new ShareLinkContent.Builder() .SetContentTitle("Hello Facebook") .SetContentDescription("The 'Hello Facebook' sample showcases simple Facebook integration") .SetImageUrl(Uri.Parse("http://developers.facebook.com/docs/android")) .Build(); if (canPresentShareDialog) { shareDialog.Show(linkContent); } else if (profile != null && HasPublishPermission()) { ShareApi.Share(linkContent, shareCallback); } else { pendingAction = PendingAction.POST_STATUS_UPDATE; } }
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); } } }
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); } }
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" }); } }
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; }