I'm using xamarin.forms (rn I only care about android) and I want to share a file from within my app to another app.
await Share.RequestAsync(new ShareFileRequest
{
Title = "Select a target",
File = new ShareFile(FilePath)
});
This works very well but depending on which file extension the file has it shows different options. In my specific case I wanna share a .docx to the LibreOffice Viewer (availabel on F-Droid). Unfortunatly it is not one of the options.
Is there a way to influence these options? It is preferred for the user to make the choose. Changing android settings manually would be accepted as a workaround.
I've searched for an android specific solution but couldn't find any. Any help is appreciated.
Thanks in advance
Well... that was a quick one :D
I've changed from Xamarin.Essentials.Share
to Xamarin.Essentials.Launcher.OpenAsync();
Now I get my target app (LibreOffice Viewer) as a possible target.
I suppose that is because the share option is usually used for social apps and I was therefore attempting to miss use it. As Jason pointed out the target app didn't register to be a sharing target for docx. Luckly it did register to open the .docx-Fileformat. My new code is:
await Launcher.OpenAsync(new OpenFileRequest()
{
File = new ReadOnlyFile(FinalFilePath),
Title = "Choose a viewer"
}) ;
Be aware that if you use Launcher.OpenAsync(filePath)
it may throw an exception. Using OpenFileRequest(...)
makes use of a dialog and enables the user to choose all availlable apps that support opening the files format.