Requirement: Share a text and image using DataTransferManager
into Facebook in Windows 10.
Problem: Unable to share image.
Below shown is the code I used,
private async void DataTransferManager_DataRequested(DataTransferManager sender, DataRequestedEventArgs args)
{
DataRequestDeferral deferral = args.Request.GetDeferral();
args.Request.Data.Properties.Title = "Sharing sample";
args.Request.Data.SetText("Testing share in universal app");
var imageUri = "http://cdn.vrworld.com/wp-content/uploads/2015/01/microsoft-announces-windows-10_ahab.1920.jpg";
//var storageFile = await StorageFile.CreateStreamedFileFromUriAsync("ShareFile", new Uri(imageUri), null);
//List<IStorageItem> storageItems = new List<IStorageItem>();
//storageItems.Add(storageFile);
//args.Request.Data.SetStorageItems(storageItems);
args.Request.Data.SetBitmap(Windows.Storage.Streams.RandomAccessStreamReference.CreateFromUri(new Uri(imageUri)));
deferral.Complete();
}
When I use SetBitmap
method, only the title and text are being shared. The image is neither displayed in the share panel nor shared to the target app.
When I use SetStorageItems
(see commented code), none of the items are shared. The default "What's on your mind" text appears on the share panel.
Any feedback is appreciated, thank you!
Sharing of URI streamed files is unfortunately not supported. Here's how I would go about doing this:
StorageFile
instance containing the file.DataRequested
handler, useSetStorageItems
to share theStorageFile
instance.I think you refer to Share Target in UWP You may refer to this URL https://github.com/Microsoft/Windows-universal-samples/tree/master/Samples/ShareSource
This sample demonstrates how an app shares content with another app. This sample uses classes from the Windows.ApplicationModel.DataTransfer namespace. Some of the classes you might want to review in more detail are the DataTransferManager class, which you use to initiate a share operation, and the DataPackage class, which you use to package the content. Because each share scenario usually involves two apps—the source app and a target app that receives the content—we recommend you install and deploy the Sharing content target app sample when you install and run this one. This way, you can see how sharing works from end to end.
This sample covers how to share content in a variety of formats, including:
1.Text 2.Web link 3.Application link 4.Images 5.Files 6.Delay-rendered files 7.HTML content 8.Custom data