在xamarin上分享图片android不适用于facebook

时间:2015-03-03 11:25:53

标签: android facebook xamarin

我正在使用此代码在android中共享文本+消息。这种方法适用于g +或电子邮件,但不适用于Facebook。它说无法加载文件。

public void Share(string title, string content)
    {
        if (ActivityContext.Current == null || Application.Context == null)
            return;

        if (string.IsNullOrEmpty(title) || string.IsNullOrEmpty(content))
            return;

        Bitmap bitmapToShare = BitmapFactory.DecodeResource(Application.Context.Resources, Resource.Drawable.icon_120);
        File pictureStorage = Environment.GetExternalStoragePublicDirectory(Environment.DirectoryPictures);
        File noMedia = new File(pictureStorage, ".nomedia");
        if (!noMedia.Exists())
            noMedia.Mkdirs();
        string imageName = "shared_image" + DateTime.Now.ToBinary() + ".png";
        File file = new File(noMedia, imageName);
        Stream output = Application.Context.OpenFileOutput(imageName,FileCreationMode.WorldReadable);
        bitmapToShare.Compress(Bitmap.CompressFormat.Png, 100, output);
        output.Flush();
        output.Close();

        // var name = Application.Context.Resources.GetResourceName(Resource.Drawable.icon_120).Replace(':', '/');
        // var imageUri = Uri.Parse("android.resource://" + name);
        var sharingIntent = new Intent();
        sharingIntent.SetAction(Intent.ActionSend);
        sharingIntent.SetType("text/plain");
        sharingIntent.SetType("image/png");
        sharingIntent.PutExtra(Intent.ExtraTitle, title);
        sharingIntent.PutExtra(Intent.ExtraText, content);
        // sharingIntent.PutExtra(Intent.ExtraStream, imageUri);
        sharingIntent.PutExtra(Intent.ExtraStream, Uri.FromFile(file));
        sharingIntent.AddFlags(ActivityFlags.GrantReadUriPermission);
        ActivityContext.Current.StartActivity(Intent.CreateChooser(sharingIntent, title));

        AnalyticsService.Instance.LogEvent("Share button clicked.");
    }

尝试了这个post。 我做错了吗?

0 个答案:

没有答案