Influence Share Options on Android (Xamarin.Forms)

huangapple go评论52阅读模式
英文:

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 Influence Share Options on Android (Xamarin.Forms)

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.

huangapple
  • 本文由 发表于 2023年4月11日 03:01:46
  • 转载请务必保留本文链接:https://go.coder-hub.com/75979894.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定