UWP sharing feature does not work on Windows 10 Mobile

I created a very simple UWP application with one button. By clicking on it , you will see a built-in sharing window for sharing the PDF file .

The fact is that I work for Windows 10 (Desktop), but it does not work for mobile devices (a pop-up window does not appear on the screen).

The PDF file is delivered as a byte array (because it will come from a remote service).

This is the code in MainPage.xaml.cs

public sealed partial class MainPage : Page
{
    public MainPage()
    {
        this.InitializeComponent();
        DataTransferManager.GetForCurrentView().DataRequested += OnDataRequested;
    }

    protected override async void OnNavigatedTo(NavigationEventArgs e)
    {
        // This should come from a service
        PdfBytes = await Microsoft.Toolkit.Uwp.StorageFileHelper.ReadBytesFromPackagedFileAsync("Document.pdf");
    }

    public byte[] PdfBytes { get; set; }

    private async void OnDataRequested(DataTransferManager sender, DataRequestedEventArgs args)
    {
        var deferral = args.Request.GetDeferral();

        var si = await StorageFile.CreateStreamedFileAsync("Document.pdf", stream =>
        {
            var writeStream = stream.AsStreamForWrite();
            writeStream.Write(PdfBytes, 0, PdfBytes.Length);
            stream.Dispose();                
        },  null);

        args.Request.Data.Properties.Title = "PDF Document";
        args.Request.Data.Properties.Description = "Some description";
        args.Request.Data.SetStorageItems(new IStorageItem[] { si });
        deferral.Complete();
    }

    private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
    {
        DataTransferManager.ShowShareUI();
    }
}

Is it correct? If this is not the case, how do I share the PDF (from its bytes)?

+3
source share
3 answers

. , CreateStreamedFileAsync Share Mobile. , , - .

TemporaryFolder, :

private async void OnDataRequested(DataTransferManager sender, DataRequestedEventArgs args)
{
    var deferral = args.Request.GetDeferral();

    var tempFile = await ApplicationData.Current.TemporaryFolder.CreateFileAsync("Document.pdf", CreationCollisionOption.ReplaceExisting);
    await FileIO.WriteBytesAsync(tempFile, PdfBytes);

    args.Request.Data.Properties.Title = "PDF Document";
    args.Request.Data.Properties.Description = "Some description";
    args.Request.Data.SetStorageItems(new IStorageItem[] { tempFile });

    deferral.Complete();
}

- , . , , , . . Temp, , , . , :

await ApplicationData.ClearAsync(ApplicationDataLocality.Temporary);
+1

, ,

private async void OnDataRequested(DataTransferManager sender, DataRequestedEventArgs args)
{
    var deferral = args.Request.GetDeferral();

    var si = await StorageFile.CreateStreamedFileAsync("Document.pdf", stream =>
    {
        var writeStream = stream.AsStreamForWrite();
        writeStream.Write(PdfBytes, 0, PdfBytes.Length);
        stream.Dispose();    

        args.Request.Data.Properties.Title = "PDF Document";
        args.Request.Data.Properties.Description = "Some description";
        args.Request.Data.SetStorageItems(new IStorageItem[] { si });
        deferral.Complete();

    },  null);
}

, , , , , , , . UWP DataTransferManager ShowShareUI() " "

0

: , . , Windows 10 mobile.

. ts working

var deferral = args.Request.GetDeferral();
deferral.Complete();
0

All Articles