英文:
Influence Share Options on Android (Xamarin.Forms)
问题
I'm using Xamarin.Forms (currently only concerned 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 the file extension, it shows different options. In my specific case, I want to share a .docx file with the LibreOffice Viewer (available on F-Droid). Unfortunately, it is not one of the options.
Is there a way to influence these options? It is preferred for the user to make the choice. 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.
英文:
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
答案1
得分: 1
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. Luckily it did register to open the .docx-File format. 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 available apps that support opening the file format.
英文:
Well... that was a quick one
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论