Language

SharedStorageAccessManager クラス

定義

Uri のアクティブ化、アプリ サービス、REST API などを使用してトークンを渡すことで、アプリが別のアプリとファイルを共有できるようにします。ターゲット アプリはトークンを引き換えて、ソース アプリによって共有されるファイルを取得します。

public ref class SharedStorageAccessManager abstract sealed
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
class SharedStorageAccessManager final
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
public static class SharedStorageAccessManager
Public Class SharedStorageAccessManager
継承
Object Platform::Object IInspectable SharedStorageAccessManager
属性

Windows の要件

要件 説明
デバイス ファミリ
Windows 10 (10.0.10240.0 で導入)
API contract
Windows.Foundation.UniversalApiContract (v1.0 で導入)

例

次の例では、ソース アプリがマッピング アプリを起動し、ターゲット アプリによって表示される駆動方向を含む .gpx ファイルを提供します。

最初に、ソース アプリは .gpx ファイルのトークンを取得し、プロトコルのアクティブ化を使用してターゲット アプリを起動します。

public async void ShareMostRecentDirections()
{
       // Get the most recently opened .gpx file
       // from the recently used file list.
       StorageItemMostRecentlyUsedList mostRecent = 
           StorageApplicationPermissions.MostRecentlyUsedList;

       String mruToken = mostRecent.Entries.FirstOrDefault().Token;
       StorageFile file = await mostRecent.GetFileAsync(mruToken);

       // Get the token to share access to the updated .gpx file.
       String sharingToken = SharedStorageAccessManager.AddFile(file);

       //Launch the driving application .
       Uri driveTo = new Uri("nokia-drive-to:?Gpxfile=" + sharingToken);
       var launch = await Launcher.LaunchURIAsync(driveTo);
}

次に、ターゲット アプリは、ソース アプリから受信したトークンを指定して .gpx ファイルを取得します。

protected override async void OnActivated(IActivatedEventArgs args)
{
    var protocolArgs = args as ProtocolActivatedEventArgs;

    // Get the token from the URI.
    var queryStrings = new WwwFormUrlDecoder(protocolArgs.Uri.Query);
    string gpxFileToken = queryStrings.GetFirstValueByName("GpxFile");

    // Get the .gpx file and call a custom method
    // to display driving directions.
    if (!string.IsNullOrEmpty(gpxFileToken))
    {
        PlotGpxFile(await
            SharedStorageAccessManager.RedeemTokenForFileAsync(gpxFileToken));
    }
}

注釈

たとえば、Uri のアクティブ化の一部としてトークンを渡すことで、アプリが別のアプリとファイルを共有できるようにする一連の手順を次に示します。

  • ソース アプリは AddFile メソッドを呼び出して、ターゲット アプリに渡す共有トークンを取得します。このトークンは Uri を使用して起動します。
  • ターゲット アプリは 、RedeemTokenForFileAsync メソッドを呼び出して共有ファイルを取得します。
  • 必要に応じて、ソース アプリで RemoveFile メソッドを呼び出し、 AddFile メソッドを呼び出して以前に取得したトークンを取り消すことができます。 Uri のアクティブ化の詳細については、「 URI の既定のアプリを起動する」を参照してください。

SharedStorageAccessManager クラスと共有トークンの使用には、次の要件と制限が適用されます。

  • 共有トークンは 1 回だけ引き換えることができます。 その後、トークンは無効になります。
  • 共有トークンは 14 日後に期限切れになり、無効になります。
  • ソース アプリは、1000 を超える共有トークンを取得できません。 ただし、トークンが引き換え、削除、または期限切れになると、ソース アプリのクォータにカウントされなくなります。

このクラスでは、ネットワーク ファイルはサポートされていません。

メソッド

Name 説明
AddFile(IStorageFile)

アプリが指定したファイルを別のアプリと共有できるようにする共有トークンを取得します。

RedeemTokenForFileAsync(String)

ソース アプリから受信した共有トークンを指定して、別のアプリによって共有されるファイルを取得します。

RemoveFile(String)

既存の共有トークンを取り消します。

適用対象