【问题标题】:Xamarin Forms can't share image to Instagram storiesXamarin Forms 无法将图像共享到 Instagram 故事
【发布时间】:2021-11-19 09:19:45
【问题描述】:

实际上,我使用此选项分享到 Instagram 故事,允许分享到每个 Instagram 选项,但现在我在要分享到 Instagram 故事时发现了错误。当我选择该选项时,会出现黑屏,没有我之前收费的图像,但只有故事、Feed 和 Direct 完美运行才会出现这种情况。

// Create the new Intent using the 'Send' action.
             Intent share = new Intent(Intent.ActionSend);

             // Add the URI to the Intent.
             share.PutExtra(Intent.ExtraStream, Uri.Parse("file://" + mediaPath));

             // Set the MIME type
             share.SetType("image/jepg");
             share.SetPackage("com.instagram.android");

             Xamarin.Forms.Forms.Context.StartActivity(Intent.CreateChooser(share, "Share image"));
             result = true;

按照文档:

https://developers.facebook.com/docs/instagram/sharing-to-stories

我可以打开 Instagram 快拍编辑器,但看不到照片,它继续黑...

 Intent share = new Intent("com.instagram.share.ADD_TO_STORY");
 Uri backgroundAssetUri = Uri.Parse("file://" + ruta);
 share.SetDataAndType(backgroundAssetUri, "image/jepg");
 share.SetFlags(ActivityFlags.GrantReadUriPermission);
    
 Xamarin.Forms.Forms.Context.StartActivity(Intent.CreateChooser(share, "Share image"));

有人可以帮我吗?

【问题讨论】:

  • 如果您使用 Xamarin.Forms,为什么不使用 Xamarin.Essentials.Share ?
  • 因为我只想将图像分享到某个目标应用程序 (Instagram),并且我需要为 Android 正确实现分享,因为 iOS 完美运行@JuanSturla
  • 很多人报告了这种行为,说这是 Instagram 的问题。您是否尝试过其他 android 版本或 instagram 版本?
  • 实际上我正在使用 Android 10 和最后一次 Instagram 更新@JuanSturla 进行所有测试

标签: android image xamarin.forms instagram share


【解决方案1】:

我找到了替代解决方案:

Uri backgroundAssetUri = Uri.Parse("file://" + ruta);
String sourceApplication = "...";
        
Intent share = new Intent("com.instagram.share.ADD_TO_STORY");
share.PutExtra("source_application", sourceApplication);
        
share.SetType("image/jepg");
share.PutExtra("interactive_asset_uri", backgroundAssetUri);
share.PutExtra("top_background_color", "#F5F5F5");
share.PutExtra("bottom_background_color", "#FFFFFF");
share.PutExtra(Intent.ExtraStream, backgroundAssetUri);
        
var activity = Xamarin.Forms.Forms.Context.GetActivity();
activity.GrantUriPermission("com.instagram.android", backgroundAssetUri, ActivityFlags.GrantReadUriPermission);
if (activity.PackageManager.ResolveActivity(share, 0) != null)
{
  activity.StartActivityForResult(share, 0);
}

我认为 Instagram 和背景的图片存在问题,因为这是我发现的将图片分享到 Instagram 快拍的唯一方法,只能使用贴纸。

【讨论】:

    猜你喜欢
    • 2019-04-06
    • 1970-01-01
    • 2019-11-08
    • 1970-01-01
    • 2018-06-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多