我正在使用此代码在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。 我做错了吗?