1

This is a followup to my previous question: Xamarin.Forms App return data to calling App

That works perfectly and I can share images to anywhere, except to Facebook comments. When I click the camera on the content box the app can be selected, I can select the image, Set result and Finish are called, and the app closes and it sends data to Facebook, and then however I then get the error : The image could not be uploaded, try again?

I can't find any fundamental differences between posting to a status or a comment, so I'm guessing it's subtle. Any thoughts on how I can change my intent to post properly? screenshot of error as shown in Facebook

Adding for completeness:

Bitmap b = null;
string url;
if (!string.IsNullOrEmpty(this.saleItems[i].ImageUrl))
{
    url = this.saleItems[i].ImageUrl;
}
else
{
    url = await FileHelper.GetLocalFilePathAsync(this.saleItems[i].Id);
}
//download
using (var webClient = new WebClient())
{
    var imageBytes = webClient.DownloadData(url);
    if (imageBytes != null && imageBytes.Length > 0)
    {
        b = BitmapFactory.DecodeByteArray(imageBytes, 0, imageBytes.Length);
    }
}
//set local path
var tempFilename = "test.png";
var sdCardPath = Android.OS.Environment.ExternalStorageDirectory.AbsolutePath;
var filePath = System.IO.Path.Combine(sdCardPath, tempFilename);
using (var os = new FileStream(filePath, FileMode.Create))
{
    b.Compress(Bitmap.CompressFormat.Png, 100, os);
}
b.Dispose();

var imageUri = Android.Net.Uri.Parse($"file://{sdCardPath}/{tempFilename}");

var sharingIntent = new Intent();
sharingIntent.SetAction(Intent.ActionSend);
sharingIntent.SetType("image/*");
sharingIntent.PutExtra(Intent.ExtraText, "some txt content");
sharingIntent.PutExtra(Intent.ExtraStream, imageUri);
sharingIntent.AddFlags(ActivityFlags.GrantReadUriPermission);

//await SaleItemDataService.Instance.BuySaleItemAsync(this.saleItem);

SetResult(Result.Ok, sharingIntent);
Finish();

This is a capture of the local stack when the intent is created, just before it does SetResult() and Finish()

Shaine Fisher
  • 315
  • 1
  • 3
  • 20
  • I know the path to the image is correct, I know it is being included in the intent, I have set permissions in the manifest for read and write external storage. This code works for Facebook, Instagram, Twitter, Messenger and WhatsApp, it is only failing for Facebook comments. Thanks – Shaine Fisher Jul 20 '17 at 17:52
  • I cannot reproduce but here are couple ideas: 1. Are you posting comment using the same user who created the original post? 2.If not, was the post created as public? – Yuri S Jul 20 '17 at 23:00
  • where can I post my comment to your post from the phone? – Yuri S Jul 20 '17 at 23:12
  • try to use another app on the phone to pick the picture. does that one goes through? – Yuri S Jul 21 '17 at 00:01
  • also try to upload photo of smaller size and may be different format – Yuri S Jul 21 '17 at 00:11
  • It's my Facebook post, and I commented, I but the post is friends only, I did a post with the same image to Facebook and twitter and that worked, size doesn't appear to be an issue, I can upload from gallery and Google photos to the same content thread. I will create a new public post and add a link here for testing, but I thanks :) – Shaine Fisher Jul 21 '17 at 05:38
  • 1
    link for testing will definitely help – Yuri S Jul 21 '17 at 06:27
  • Test tweet, the same happens on tweet comments too, but the original photo was posted to Twitter from the app, https://mobile.twitter.com/iamshainefisher/status/888286371902668800 – Shaine Fisher Jul 21 '17 at 06:37
  • Facebook post https://m.facebook.com/story.php?story_fbid=1776863145937611&id=100008418289054 and is public :) – Shaine Fisher Jul 21 '17 at 06:44
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/149835/discussion-between-yuri-s-and-shaine-fisher). – Yuri S Jul 21 '17 at 17:34

1 Answers1

1

Use below:

        Intent sharingIntent = new Intent();
        string imageUri = "file://" + requestedUri;
        sharingIntent.SetData(Android.Net.Uri.Parse(imageUri));
Yuri S
  • 5,355
  • 1
  • 15
  • 23
  • As I said earlier, this is where I started with the original problem, in so happy I was right to start with, sadly I got lost trying to solve two slightly different problems at the same time. Thanks for your help, again. – Shaine Fisher Jul 21 '17 at 18:11