1
我试图创建一个功能,让我分享能够通过androids共享对话,共享图像到任何支持申请例如。松弛,Outlook等Xamarin Android - 共享图像从应用程序结果没有图像显示,并在Android的Outlook IO错误
但是,当我运行下面的代码完成没有错误的图像不会出现在我分享给任何应用程序和Outlook来回android给出一个通用的IO错误。
async void shareMetricFromURL(){
WebClient webClient = new WebClient();
var url = new Uri ("https://upload.wikimedia.org/wikipedia/commons/thumb/0/02/Stack_Overflow_logo.svg/500px-Stack_Overflow_logo.svg.png");
byte[] bytes = null;
try{
bytes = await webClient.DownloadDataTaskAsync(url);
}
catch(TaskCanceledException){
return;
}
catch(Exception e){
return;
}
string documentsPath = Android.OS.Environment.GetExternalStoragePublicDirectory(Android.OS.Environment.DirectoryPictures).ToString();
string localFilename = "downloaded.png";
string localPath = System.IO.Path.Combine (documentsPath, localFilename);
//Sive the Image using writeAsync
FileStream fs = new FileStream (localPath, FileMode.OpenOrCreate);
await fs.WriteAsync (bytes, 0, bytes.Length);
fs.Close();
var sendIntent = new Intent();
sendIntent.SetAction(Intent.ActionSend);
var uri = Android.Net.Uri.FromFile(new Java.IO.File(localPath));
sendIntent.PutExtra(Intent.ExtraStream, uri);
sendIntent.SetType("image/*");
StartActivityForResult(Intent.CreateChooser(sendIntent, "Share With..."), 0);
}
有什么想法?