SharedStorageAccessManager
SharedStorageAccessManager
SharedStorageAccessManager
SharedStorageAccessManager
Class
Definition
Enables an app to share a file with another app by passing a token via Uri activation, app service, REST API, etc. The target app redeems the token to get the file shared by the source app.
public : static class SharedStorageAccessManagerpublic static class SharedStorageAccessManagerPublic Static Class SharedStorageAccessManager// You can use this class in JavaScript.
- Attributes
| Device family |
Windows 10 (introduced v10.0.10240.0)
|
| API contract |
Windows.Foundation.UniversalApiContract (introduced v1)
|
Examples
In the following example, a source app launches a mapping app and provides a .gpx file that contains driving directions to be displayed by the target app.
First, the source app gets a token for the .gpx file and uses protocol activation to launch the target app.
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);
}
Next, the target app gets the .gpx file by providing the token received from the source app.
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));
}
}
Remarks
Here is the sequence of steps that enables an app to share a file with another app by passing a token as part of a Uri activation, for example.
- The source app calls the AddFile method to get the sharing token that it passes to the target app, which it launches with a Uri.
- The target app calls the RedeemTokenForFileAsync method to get the shared file.
- Optionally, the source app can call the RemoveFile method to revoke a token that it obtained previously by calling the AddFile method. For more info about Uri activation, see Launch the default app for a URI.
The use of the SharedStorageAccessManager class and of sharing tokens is subject to the following requirements and restrictions.
- A sharing token can only be redeemed one time. After that, the token is no longer valid.
- A sharing token expires after 14 days and is no longer valid.
- The source app cannot get more than one thousand sharing tokens. After a token is redeemed, removed, or expires, however, it no longer counts against the quota of the source app.
Network files are not supported with this class.
Methods
AddFile(IStorageFile) AddFile(IStorageFile) AddFile(IStorageFile) AddFile(IStorageFile)
Gets the sharing token that enables an app to share the specified file with another app.
public : static PlatForm::String AddFile(IStorageFile file)public static string AddFile(IStorageFile file)Public Static Function AddFile(file As IStorageFile) As string// You can use this method in JavaScript.
The file to share with the target app.
The sharing token to provide to the target app .
Remarks
When a source app shares a file with a target app, the source app calls the AddFile method to get the sharing token that it passes to the target app.
For a code sample, see SharedStorageAccessManager.
RedeemTokenForFileAsync(String) RedeemTokenForFileAsync(String) RedeemTokenForFileAsync(String) RedeemTokenForFileAsync(String)
Gets a file shared by another app by providing the sharing token received from the source app.
public : static IAsyncOperation<StorageFile> RedeemTokenForFileAsync(PlatForm::String token)public static IAsyncOperation<StorageFile> RedeemTokenForFileAsync(String token)Public Static Function RedeemTokenForFileAsync(token As String) As IAsyncOperation( Of StorageFile )// You can use this method in JavaScript.
- token
- PlatForm::String String String String
The sharing token for the shared file.
A wrapper object that contains the shared file.
Remarks
When a source app shares a file with a target app, the target app calls the RedeemTokenForFileAsync method to get the shared file.
For a code sample, see SharedStorageAccessManager.
RemoveFile(String) RemoveFile(String) RemoveFile(String) RemoveFile(String)
Revokes an existing sharing token.
public : static void RemoveFile(PlatForm::String token)public static void RemoveFile(String token)Public Static Function RemoveFile(token As String) As void// You can use this method in JavaScript.
- token
- PlatForm::String String String String
The sharing token to revoke.
Remarks
The source app can optionally call the RemoveFile method to revoke a token that it obtained previously by calling the AddFile method.