I have made my app a Share Target (and Source), and I can successfully Share my app's content with other apps, but when I am in another app, like Mail or IE for example, I cannot share their content with my app because it doesn't appear in the Share Pane as an available Share Target app.
I have read and followed the MSDN documentation, checked out the samples, and have also setup the Share Target Declaration in the Package.AppXManifest file.
Why, and how can I fix this?
C# Code-behind:
ShareOperation shareOperation;
private string sharedDataTitle;
private string sharedDataDescription;
private string shareQuickLinkId;
private string sharedText;
private Uri sharedUri;
private IReadOnlyList<IStorageItem> sharedStorageItems;
private string sharedCustomData;
private string sharedHtmlFormat;
private IReadOnlyDictionary<string, RandomAccessStreamReference> sharedResourceMap;
private IRandomAccessStreamReference sharedBitmapStreamRef;
private IRandomAccessStreamReference sharedThumbnailStreamRef;
private void ReportStarted()
{
this.shareOperation.ReportStarted();
}
private void ReportCompleted()
{
this.shareOperation.ReportCompleted();
}
protected override async void OnNavigatedTo(NavigationEventArgs e)
{
RegisterForShare();
try
{
this.shareOperation = (ShareOperation)e.Parameter;
await Task.Factory.StartNew(async () =>
{
ReportStarted();
// Retrieve data package properties.
this.sharedDataTitle = this.shareOperation.Data.Properties.Title;
this.sharedDataDescription = this.shareOperation.Data.Properties.Description;
this.shareQuickLinkId = this.shareOperation.QuickLinkId;
// Retrieve data package content.
if (this.shareOperation.Data.Contains(StandardDataFormats.Text))
{
try
{
this.sharedText = await this.shareOperation.Data.GetTextAsync();
}
catch (Exception exception)
{
// NotifyUser of error.
}
}
else if(this.shareOperation.Data.Contains(StandardDataFormats.Html))
{
try
{
this.sharedHtmlFormat = await this.shareOperation.Data.GetHtmlFormatAsync();
}
catch (Exception exception)
{
}
}
else if (this.shareOperation.Data.Contains(StandardDataFormats.Uri))
{
try
{
this.sharedUri = await this.shareOperation.Data.GetUriAsync();
}
catch (Exception exception)
{
}
}
// Get back to the UI thread.
await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async () =>
{
if (this.sharedText != null)
{
// Create a Note out of shared data.
CreateNote(this.sharedDataTitle, this.sharedText, null);
this.shareOperation.ReportDataRetrieved();
}
if (this.sharedUri != null)
{
CreateNote(this.sharedDataTitle, this.sharedUri.OriginalString, null);
this.shareOperation.ReportDataRetrieved();
}
if (this.sharedHtmlFormat != null)
{
CreateNote(this.sharedDataTitle, this.sharedHtmlFormat.ToString(), null);
this.shareOperation.ReportDataRetrieved();
}
});
});
}
catch (Exception exception)
{
Debug.WriteLine(exception.Message);
}
if (e.NavigationMode == NavigationMode.Back)
{
navigatedBack = true;
}
base.OnNavigatedTo(e);
}
App.xaml.cs:
protected override void OnShareTargetActivated(ShareTargetActivatedEventArgs args)
{
var rootFrame = new Frame();
rootFrame.Navigate(typeof(MainPage), args.ShareOperation);
Window.Current.Content = rootFrame;
Window.Current.Activate();
}
Any help will be greatly appreciated.