【发布时间】:2018-02-22 22:09:22
【问题描述】:
我正在使用 post call 来获取包含 PDF 的所有数据的字节流,然后我想使用 Android 中的默认程序打开 PDF。稍后会为 iOS 做。
这是我的代码:
async void OnItemSelected(object sender, SelectedItemChangedEventArgs e)
{
Publication p = (Publication)e.SelectedItem;
Debug.WriteLine(p);
if (p.folderID.Equals("-1"))
{
using (Stream respStream = await post(p.docNum))
{
byte[] buffer = new byte[respStream.Length];
respStream.Read(buffer, 0, buffer.Length);
string path = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
File.WriteAllBytes(path + "foo.pdf", buffer);
Device.OpenUri(new Uri(path + "foo.pdf"));
}
}
else
{
await Navigation.PushAsync(new PublicationsPage(p.folderID));
}
}
private async Task<Stream> post(string id)
{
Dictionary<string, string> dir = new Dictionary<string, string>();
dir.Add("LoginID", App.user.login_id);
dir.Add("docID", id);
var jsonReq = JsonConvert.SerializeObject(dir);
Debug.WriteLine("req: " + (String)jsonReq);
var content = new StringContent(jsonReq, Encoding.UTF8, "application/json");
var response = await client.PostAsync(url, content);
var responseStream = await response.Content.ReadAsStreamAsync();
return responseStream;
}
我现在将 pdf 作为字节流下载,然后弹出一个窗口然后关闭。我该怎么做才能解决?我宁愿不为任何软件包付费,理想情况下我希望它提示要打开什么程序。
【问题讨论】:
标签: c# android json xamarin io