I'm writing application using Xamarin.forms and i need to open PDF and Doc documents in Droid and IOS. Is there any crossplatform way to achive this? Maybe any packages?
2 Answers
Now you can use the Launcher class by adding a reference to Xamarin.Essentials in your class.
For opening a file by another application use:
await Launcher.OpenAsync(new OpenFileRequest
{
File = new ReadOnlyFile(file)
});
Where file is the File or FullPath.
You can find more here: https://learn.microsoft.com/en-us/xamarin/essentials/launcher?tabs=android

- 91
- 1
- 3
It depends on what type of documents you are taking about. In Xamarin.Forms, you can use
Device.OpenUri(new Uri("filepath or http url"));
If there is an application that can handle the extension, then it will prompt you on which app you wish to use.
If you wanted to view them internally, inside the app, without launching a 3rd party app, then we really need to know what type of documents you are opening. If it's a PDF, then you can look at Display Local PDF File In WebView.
Should it be another type of document, you will need to see if there is a different

- 16,089
- 6
- 66
- 109
-
This is not working on `Android` as it causes a `Android.OS.FileUriExposedException`. – zimmerrol Dec 13 '17 at 21:00
-
This blog article helped me fixing the Android exception: https://medium.com/p/70b9eb17c6d0 – Gabriel Weidmann Nov 14 '19 at 10:20
-
1This is now obsolete. – Edgaras May 26 '20 at 09:35