4

要件:DataTransferManager Windows 10 で Facebook を使用してテキストと画像を共有します。

問題:画像を共有できません。

以下に示すのは、私が使用したコードです。

 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();
        }

メソッドを使用SetBitmapすると、タイトルとテキストのみが共有されます。画像は共有パネルに表示されず、ターゲット アプリにも共有されません。

私が使用するとSetStorageItems(コメント付きのコードを参照)、共有されるアイテムはありません。デフォルトの「What's on your mind」テキストが共有パネルに表示されます。

フィードバックをお待ちしております。

4

2 に答える 2

3

残念ながら、URI ストリーミング ファイルの共有はサポートされていません。これを行う方法は次のとおりです。

  1. ユーザーが共有ボタンをクリックすると、ファイルのダウンロードが開始され、大きなファイルの場合は何らかの進行状況が表示されます。もちろん、ファイルを事前にダウンロードすることもできます。StorageFileファイルを含むインスタンスを セットアップします。
  2. DataTransferManager.ShowShareUI を呼び出す
  3. DataRequestedハンドラーで、インスタンスSetStorageItemsを共有するために使用します。StorageFile
于 2015-05-13T01:05:13.117 に答える
-3

UWP の Share Target を参照していると思います この URL を参照できます https://github.com/Microsoft/Windows-universal-samples/tree/master/Samples/ShareSource

このサンプルは、アプリが別のアプリとコンテンツを共有する方法を示しています。このサンプルでは、​​Windows.ApplicationModel.DataTransfer 名前空間のクラスを使用します。共有操作を開始するために使用する DataTransferManager クラスと、コンテンツをパッケージ化するために使用する DataPackage クラスなど、より詳細に確認する必要があるクラスがあります。通常、各共有シナリオには 2 つのアプリ (ソース アプリと、コンテンツを受け取るターゲット アプリ) が含まれるため、このサンプルをインストールして実行するときに、共有コンテンツ ターゲット アプリのサンプルをインストールして展開することをお勧めします。このようにして、共有がどのように機能するかを端から端まで確認できます。

このサンプルでは、​​次のようなさまざまな形式でコンテンツを共有する方法について説明します。

1.テキスト 2.Web リンク 3.アプリケーション リンク 4.画像 5.ファイル 6.遅延レンダリング ファイル 7.HTML コンテンツ 8.カスタム データ

protected override bool GetShareContent(DataRequest request)
    {
        bool succeeded = false;

        if (this.imageFile != null)
        {
            DataPackage requestData = request.Data;
            requestData.Properties.Title = TitleInputBox.Text;
            requestData.Properties.Description = DescriptionInputBox.Text; // The description is optional.
            requestData.Properties.ContentSourceApplicationLink = ApplicationLink;

            // It's recommended to use both SetBitmap and SetStorageItems for sharing a single image
            // since the target app may only support one or the other.

            List<IStorageItem> imageItems = new List<IStorageItem>();
            imageItems.Add(this.imageFile);
            requestData.SetStorageItems(imageItems);

            RandomAccessStreamReference imageStreamRef = RandomAccessStreamReference.CreateFromFile(this.imageFile);
            requestData.Properties.Thumbnail = imageStreamRef;
            requestData.SetBitmap(imageStreamRef);
            succeeded = true;
        }
        else
        {
            request.FailWithDisplayText("Select an image you would like to share and try again.");
        }
        return succeeded;
    }
于 2015-10-31T09:48:48.370 に答える