using Xamarin.Essentials;
namespace myNamespace
{
class myClass
{
public async void OpenFile(string path)
{
await Launcher.OpenAsync(new OpenFileRequest("File", new ReadOnlyFile(path)));
}
}
}
It works well if path
is a real file system path, and doesn't work if it is a URI, giving an error like:
System.IO.DirectoryNotFoundException: 'Could not find a part of the path "content://com.android.providers.downloads.documents/something".'
(I'm getting path
using Xamarin.Plugin.FilePicker, so it should be a real file, but sometimes the FilePicker returns URI instead of a path. For example, if I pick an image from camera it returns a path, and if I pick a file from Downloads, it returns a URI).