I'm using a post call to get a byte stream with all the data for a PDF, then I want to open the PDF using the default program in Android. Will later do for iOS.
Here's my code:
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; } What I have now downloads the pdf as a byte stream then makes a window pop up then close. What should I do to fix? I'd rather not pay for any packages and ideally I'd like to have it prompt for what program to open with.