WP 8.1 Share Contracts Issue

ishaan_666

New member
Mar 29, 2013
44
0
0
I'm trying to share an image through my app, everything works just fine when I run the app on my phone through visual studio, but when I try to run it from my phone, it crashes everytime I click the share button.

private async void dataTransferManager_DataRequested(DataTransferManager sender, DataRequestedEventArgs args)
{
args.Request.Data.Properties.Title = "Let's Celebrate";
args.Request.Data.Properties.Description = "It's time to celebrate!";
DataRequestDeferral deferral = args.Request.GetDeferral();
try
{
var finalImg = await GenerateImage();

var folder = Package.Current.InstalledLocation;
const CreationCollisionOption option = CreationCollisionOption.ReplaceExisting;
var file = await folder.CreateFileAsync("letscelebrateshare.png", option);
var logicalDpi = DisplayInformation.GetForCurrentView().LogicalDpi;
var pixelBuffer = await finalImg.GetPixelsAsync();

using (var stream = await file.OpenAsync(FileAccessMode.ReadWrite))
{
var encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.PngEncoderId, stream);
encoder.SetPixelData(
BitmapPixelFormat.Bgra8,
BitmapAlphaMode.Premultiplied,
(uint)finalImg.PixelWidth,
(uint)finalImg.PixelHeight,
logicalDpi,
logicalDpi,
pixelBuffer.ToArray());

await encoder.FlushAsync();

StorageFile logoFile =
await Package.Current.InstalledLocation.GetFileAsync("letscelebrateshare.png");
List<IStorageItem> storageItems = new List<IStorageItem>();
storageItems.Add(logoFile);
args.Request.Data.SetStorageItems(storageItems);
}
}
finally
{
deferral.Complete();
}

}

Help please?
 
I'm trying to share an image through my app, everything works just fine when I run the app on my phone through visual studio, but when I try to run it from my phone, it crashes everytime I click the share button.



Help please?

Ishaan, I am not a dev, but I appreciate the frustration when something doesn't work the way it should. You might also try posting in the Windows Dev Community.

https://dev.windowsphone.com/en-us/community

If you feel more comfortable communicating in another language, there is a language selection button at the very bottom of the page.
 
I see a try statement with a finally, but not a catch. Try catching a (general) Exception object and print out the error. If it's not going to bottleneck things, try showing a MessageDialog with the error. Visual Studio will tell you you you can't await an async function in a catch clause, but you can get around that by calling the async function as a task and get it's awaiter

Catch(Exception ex) {
MessageDialog dlg = new MessageDialog("the error was: " + ex.message);
dlg.ShowAsync().AsTask().GetAwaiter();
}
 

Members online

No members online now.

Forum statistics

Threads
335,634
Messages
2,258,640
Members
428,749
Latest member
amiee