-
Notifications
You must be signed in to change notification settings - Fork 501
Share: Share Documents/Files #425
Comments
1.1.0 has file sharing! |
[VS sync] The field 'Milestone' contains the value '1.1.0' that is not in the list of supported values |
Nice to see this land! I gave it a spin on Android with code along these lines: string filePath = path to a PDF;
string contentType = "application/pdf";
ShareFile share = new ShareFile(filePath, contentType);
ShareFileRequest request = new ShareFileRequest(Path.GetFileName(filePath), share);
await Share.RequestAsync(request); It worked, in that a system dialog opened with some apps as options. However, the apps were Gmail, Save to Drive, and Messages, aka generic options. If I use the more traditional approach (e.g. https://www.syncfusion.com/kb/8707/how-to-share-the-pdf-document-in-xamarin-forms-platform), I get PDF-specific options, such as "Drive PDF Viewer". Is there some setup required before the feature will work as expected? Thanks. |
You will need to enable the experimental features: // Enable currently experimental features Under the hood it calls: var contentUri = Platform.GetShareableFileUri(request.File.FullPath);
var intent = new Intent(Intent.ActionSend);
intent.SetType(request.File.ContentType);
intent.SetFlags(ActivityFlags.GrantReadUriPermission);
intent.PutExtra(Intent.ExtraStream, contentUri);
if (!string.IsNullOrEmpty(request.Title))
{
intent.PutExtra(Intent.ExtraTitle, request.Title);
}
var chooserIntent = Intent.CreateChooser(intent, request.Title ?? string.Empty);
chooserIntent.SetFlags(ActivityFlags.ClearTop);
chooserIntent.SetFlags(ActivityFlags.NewTask);
Platform.AppContext.StartActivity(chooserIntent);
return Task.CompletedTask; Which looks pretty much identical to what is in that article, so should work. |
@jamesmontemagno: I spent a little more time on this. Ultimately, it's a question of intent. :-) My app currently does the following:
This results in the following system dialog: Using the I have no basis for judging which of the two intents is preferable for an abstraction that involves sharing files. My particular use case is to launch an external viewer, and |
Ahhhhh yes, this makes sense! Good call. The API is still not final so we can easily play around with this. I think we can add an intention on it. Or we can have "ShareFileRequest" and "ViewFileRequest".. @Redth The question is... is it different in UWP and iOS at all? |
Re-opening for now since we are reving the API |
UWP distinguishes between launching a file ( |
[VS sync] The field 'Milestone' contains the value '1.1.1' that is not in the list of supported values |
Hi friends for android version > 24 you need to use fileProvider class use : Uri uri = FileProvider.getUriForFile(MainActivity.this, BuildConfig.APPLICATION_ID + ".provider",fileImagePath); InsteadOf : Uri uri = Uri.fromFile(fileImagePath); Just Implemented On my app |
@jamesmontemagno, maybe this is where we should be using the launcher to open files and the share to share? This may mean we have to extend the launcher apis |
Agreed with @mattleibow above. I don't want to appear rude (I am grateful for all of the effort on this project) and I would prefer to use a Xamarin.Essentials function for opening files but its hard to make decisions without knowing a little more. Is work already underway on this? |
@RhomGit the ability to share is already integrated into 1.1.0 and we re-opened this to expand to opening the file. We are working on new features and bug fixes regularly. |
Closing now as API is in 1.2.0-pre shipping soon :) |
…arin#773) * Implement Open File in Launcher. Fixed xamarin#601 & xamarin#425 * Add title to open file request for android launcher * Clean FileBase and AttachmentName. Added documentation. * Fix encoding * Remove namesapces that aren' t needed
Hi,
Please add an option to Share Documents with a Title and URL..
For example, share PDF in Whatsapp or Google Drive or One Drive or DropBox..
Thanks,
Jassim
The text was updated successfully, but these errors were encountered: