Presentation is loading. Please wait.

Presentation is loading. Please wait.

Sharing Files and Data in Windows Phone 8.1

Similar presentations


Presentation on theme: "Sharing Files and Data in Windows Phone 8.1"— Presentation transcript:

1 Sharing Files and Data in Windows Phone 8.1
WP8.1 Jump Start Building Apps for Windows Phone 8.1 Jump Start Sharing Files and Data in Windows Phone 8.1 Andy Wigley @andy_wigley Matthias Shapiro @matthiasshap 29 April 2014

2 In this module… App to app communication Sharing data with other apps
File Associations Uri Associations Sharing data with other apps Making your app a Share source Implementing a Share target Opening and Saving files with the File open and save pickers Programming the File Open and File Save Pickers in your app Implementing File Open and File Save Provider capability in an app

3 Sharing in Windows Phone 8.1
11/7/2018 Sharing in Windows Phone 8.1 Shell Uri association Windows.System.Launcher.LaunchUriAsync( new Uri("jumpstart:NewSession?ID=aea6")); Data in Uri File association Data in File Windows.System.Launcher.LaunchFileAsync( myStorageFile); Share contract File, text, HTML, image, custom data in DataPackage Share transient UI Windows.ApplicationModel.DataTransfer. DataTransferManager.ShowShareUI(); © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

4 Differences from Windows
11/7/2018 Differences from Windows On Windows, user manages programs to launch for a file extension or protocol in the Set Associations settings On Windows Phone, if more than one match, shell prompts user for the program to launch. Windows Store Apps supports Share contract and Settings contract. Launched from Charms bar. On Windows Phone, there is no Charms bar. Only Share contract is supported. App will implement its own UI for Settings. © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

5 File and Uri Associations

6 Custom URI Associations
11/7/2018 Custom URI Associations Launch other apps to complete tasks Launch another app and pass it data Play an album on Spotify Play a video in YouTube Launch device settings Link into core experiences Browser (http) Messaging (mailto:) await Launcher.LaunchUriAsync(new Uri("fb://profile/1234")); © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

7 Custom URI Associations
11/7/2018 Custom URI Associations What’s new? Added support for new LauncherOptions FallbackUri await Launcher.LaunchUriAsync( new Uri("fb://profile/1234"), new LauncherOptions { FallbackUri = new Uri(" } ); © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

8 File Type Associations
11/7/2018 File Type Associations Launch files in the right app Microsoft Office Adobe Reader Handle custom files in your app from Another app Browser Office Hub var file = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appdata://Local/mydoc.pdf")); await Launcher.LaunchFileAsync(file); © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

9 Registering File and/or Uri Associations (Target)
Windows Runtime Apps Registering File and/or Uri Associations (Target)

10 Handling File Activation (Windows Runtime Apps)
11/7/2018 Handling File Activation (Windows Runtime Apps) protected override async void OnFileActivated(FileActivatedEventArgs args) { // Handle file activation. The number of files received is args.Files.Size. First file is args.Files[0].Name Frame rootFrame = Window.Current.Content as Frame; ... // Standard Frame initialization code ... if (rootFrame.Content == null) if (!rootFrame.Navigate(typeof(BugQueryPage))) { throw new Exception("Failed to create initial page"); } } var p = rootFrame.Content as BugQueryPage; // Pass the File activation args to a property you’ve implemented on the target page p.FileEvent = args; Window.Current.Activate(); © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

11 Handling Uri Activation (Windows Runtime Apps)
11/7/2018 Handling Uri Activation (Windows Runtime Apps) public partial class App { ... protected override void OnActivated(IActivatedEventArgs args) if (args.Kind == ActivationKind.Protocol) ProtocolActivatedEventArgs eventArgs = args as ProtocolActivatedEventArgs; // TODO: Handle URI activation // The received URI is eventArgs.Uri.AbsoluteUri } © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

12 Demo File and Uri Associations

13 11/7/2018 Share Contract © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

14 Sharing isn’t New to Windows Phone
11/7/2018 Sharing isn’t New to Windows Phone Internal apps Silverlight 8 apps (ShareLinkTask/ShareStatusTask) © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

15 Windows 8.1 Share Contract Extends Sharing
11/7/2018 Windows 8.1 Share Contract Extends Sharing Enable user-driven sharing between apps Apps can freely share content from Source to Target No distinctions between 1st and 3rd party capabilities No limitations on content type Works well on low-cost devices Available for Windows XAML and Silverlight 8.1 apps Many apps will be Share source Most apps have something worth sharing Only a few apps will be a Share target © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

16 Share Source and Share Target
11/7/2018 Share Source and Share Target Share Source Using this contract tells Windows that your app can provide data (files, text, images, more) to other apps. Many apps will be a share source. Share Target Implementing share target means that your app can be on the receiving end of data from other apps. Relatively few apps will be share target. Helps centralize the interface to a potentially volatile back-end An or social networking app could receive images and text from any other app, and thereby serve as the primary interface for that social network. Other apps do not need to understand the protocols or APIs just to send information. © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

17 Integration with Built-In Sharing
11/7/2018 Integration with Built-In Sharing Built-In Sources Single Photo Viewer (Photos) IE (Web pages) Xbox Music (Music/video URI) Office (Documents) Contacts (vcard file) Built-In Targets (text/URI/files) Messaging (text/URI) Tap+Send (URI/files) Bluetooth (files) OneNote (text/URI/pictures) Rooms (files) © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

18 11/7/2018 Share Contract UX © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

19 Sharing From Source to Target
Source app Share picker (Shell) Share target app Registers with the DataTransfer Manager User selects “Share” charm (Windows) User selects “Share” UI (Windows Phone) Active app is sent event Receives event and fills DataPackage Filters list of Target Apps Completes Async calls and returns User selects Target App Activated for sharing Activate Target as kind shareTarget DataPackage lives in source application Processes DataPackage contents Reports Complete

20 Implementing a Share Source

21 Implementing share source
11/7/2018 Implementing share source protected override void OnNavigatedTo(NavigationEventArgs e) { navigationHelper.OnNavigatedTo(e); DataTransferManager.GetForCurrentView().DataRequested += OnShareDataRequested; } protected override void OnNavigatedFrom(NavigationEventArgs e) navigationHelper.OnNavigatedFrom(e); DataTransferManager.GetForCurrentView().DataRequested -= OnShareDataRequested; private void AppBarButton_Click(object sender, RoutedEventArgs e) DataTransferManager.ShowShareUI(); ! Always remove your event handlers Always tear down your event handlers when you’re done with them © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

22 Implementing share source
11/7/2018 Implementing share source // Handle DataRequested event and provide DataPackage void OnShareDataRequested(DataTransferManager sender, DataRequestedEventArgs args) { var request = args.Request; request.Data.Properties.Title = "Share example"; //You MUST set a Title! request.Data.Properties.Description = "This demonstrates how to share text to another app"; request.Data.SetText(TextToShare.Text.Trim()); } Title You must set a Title on the Data Package. If you do not, the Share operation silently fails (no exception). Description Not used by the Share UI on Windows Phone (used by the Windows Share UI), but is available to the Share target. © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

23 Including Files in Data Package
11/7/2018 Including Files in Data Package // Handle DataRequested event and provide DataPackage async void OnShareDataRequested(DataTransferManager sender, DataRequestedEventArgs args) { var dp = args.Request.Data; var deferral = args.Request.GetDeferral(); var photoFile = await StorageFile.GetFileFromApplicationUriAsync( new Uri("ms-appx:///Assets/needle.jpg")); dp.Properties.Title = "Space Needle"; dp.Properties.Description = "The Space Needle in Seattle, WA"; dp.SetStorageItems(new List<StorageFile> { photoFile }); dp.SetWebLink(new Uri(" deferral.Complete(); } Deferrals You need to use deferrals when there is an async operation in the request. © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

24 Data Package Data Formats
11/7/2018 Data Package Data Formats Method Comments SetApplicationLink(Uri value) A Uri back to the source application (a Uri association) SetBitmap(RandomAccessStreamReference value) A bitmap image SetData(string formatId, object value) Used in a delayed rendering callback method to supply the data SetDataProvider(string formatId, DataProviderHandler delayRenderer) Declares a callback method for delayed rendering of data items, if acquisition of data for sharing is time-consuming SetHtmlFormat(string value) HTML content SetRtf(string value) RTF formatted text SetStorageItems(IEnumerable<IStorageItem> value, bool readOnly) One or more files and/or folders SetText(string value) Simple text SetWebLink(Uri value) Link to a resource on the network © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

25 Sharing Source demo

26 Implementing a Share Target

27 Registering as a Share Target
Register supported formats and file types in the Manifest: Plain text Formatted text URI HTML Images Files Custom data formats

28 Share Target Activation (Windows Runtime Apps)
11/7/2018 Share Target Activation (Windows Runtime Apps) // Override OnShareTargetActivated and redirect user to sharing page protected override void OnShareTargetActivated(ShareTargetActivatedEventArgs args) { Frame rootFrame = Window.Current.Content as Frame; if (rootFrame == null) rootFrame = new Frame(); Window.Current.Content = rootFrame; } if (rootFrame.Content == null) rootFrame.Navigate(typeof(SharePage), args.ShareOperation); Window.Current.Activate(); © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

29 Acting as a Share Target (Windows Runtime App + Silverlight)
11/7/2018 Acting as a Share Target (Windows Runtime App + Silverlight) // This code in the transient UI (Share target page) handles the Data Package. protected override async void OnNavigatedTo(NavigationEventArgs e) { shareOp = e.Parameter as ShareOperation; TitleTextBlock.Text = shareOp.Data.Properties.Title; DescriptionTextBlock.Text = shareOp.Data.Properties.Description; SharedTextTextBlock.Text = await shareOp.Data.GetTextAsync(); var photoFile = (StorageFile)(await shareOp.Data.GetStorageItemsAsync())[0]; var imageSource = new BitmapImage(); imageSource.SetSource(await photoFile.OpenReadAsync()); sharedPhotoImage.Source = imageSource; } © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

30 Acting as a Share Target
11/7/2018 Acting as a Share Target // Call ReportCompleted when done to return user to source app private void Button_Click(object sender, RoutedEventArgs e) { shareOp.ReportCompleted(); } © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

31 Creating a Share Target
demo

32 Sharing Best Practices
Sources Share multiple formats of your content (if possible) Use ApplicationLink/WebLink rather than URI Targets Keep sharing UX self-contained – no Home button! Hand off large uploads to the Background Transfer API Always call ReportCompleted to send the user back to where they came from

33 Share contract comparison with Windows
11/7/2018 Share contract comparison with Windows Complete API convergence Phone-specific behavior No long running shares – Share Target is transient and is not kept alive We do not support Quicklinks Source application will be suspended when Share is invoked Source application may be terminated while Share is running © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

34 Picker Contracts

35 Pickers aren’t new to Windows Phone
11/7/2018 Pickers aren’t new to Windows Phone Silverlight 8 apps (PhotoChooserTask) © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

36 WP 8.1 FileOpenPicker/FileSavePicker UX
11/7/2018 WP 8.1 FileOpenPicker/FileSavePicker UX Other apps… Your app Provider selection (shell) Provider UI Your app © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

37 Picker Goals Apps shouldn’t care where files come from or go to
11/7/2018 Picker Goals Apps shouldn’t care where files come from or go to Apps can access any type of file Allows an app to access files that are not in the app data folders Access files in Pictures Library, Videos Library without KnownFolders API needing Capability declaration – permission is implied since the user selects the file Seamlessly go out to the cloud, phone or an app to get a file Support both Open and Save Save to the cloud, phone or an app Update latest changes as required (handled by the provider) Work well on low-cost devices Available for Windows XAML and Silverlight 8.1 © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

38 File Picker Client App

39 App activated when file picked
11/7/2018 Picker Contracts – Pick a File Usage Differs on Windows and Windows Phone Windows Windows Phone //Create the picker object FileOpenPicker openPicker = new FileOpenPicker(); openPicker.ViewMode = PickerViewMode.Thumbnail; openPicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary; // Users expect to have a filtered view of their folders openPicker.FileTypeFilter.Add(".jpg"); openPicker.FileTypeFilter.Add(".png"); // Open the picker for the user to pick a file StorageFile file = await openPicker.PickSingleFileAsync(); if (file != null) { // Do something with the file... } //Create the picker object FileOpenPicker openPicker = new FileOpenPicker(); // Users expect to have a filtered view of their folders openPicker.FileTypeFilter.Add(".jpg"); openPicker.FileTypeFilter.Add(".png"); // Open the picker for the user to pick a file openPicker.ContinuationData["Operation"] = "SomeDataOrOther"; openPicker.PickSingleFileAndContinue(); App suspended, may be terminated App activated when file picked © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

40 11/7/2018 Activation after File Picker (Windows Runtime Apps) 1 of 2 – App.xaml.cs protected override async void OnActivated(IActivatedEventArgs args) { if (args is FileOpenPickerContinuationEventArgs) Frame rootFrame = Window.Current.Content as Frame; ... // Standard Frame initialization code ... if (!rootFrame.Navigate(typeof(ProfilePage))) throw new Exception("Failed to create target page"); } var p = rootFrame.Content as ProfilePage; p.FilePickerEvent = (FileOpenPickerContinuationEventArgs)args; // Ensure the current window is active Window.Current.Activate(); © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

41 11/7/2018 Activation after File Picker (Windows Runtime Apps) 2 of 2 – Page where picker was initiated private FileOpenPickerContinuationEventArgs _filePickerEventArgs = null; public FileOpenPickerContinuationEventArgs FilePickerEvent { get { return _filePickerEventArgs; } set { _filePickerEventArgs = value; ContinueFileOpenPicker(_filePickerEventArgs); } } public async void ContinueFileOpenPicker(FileOpenPickerContinuationEventArgs args) if ((args.ContinuationData["Operation"] as string) == "SomeDataOrOther" && args.Files != null && args.Files.Count > 0) StorageFile file = args.Files[0]; IRandomAccessStream fileStream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read); BitmapImage bitmapImage = new BitmapImage(); bitmapImage.SetSource(fileStream); ProfilePic.Source = bitmapImage; © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

42 App activated when file picked
11/7/2018 Picker Contracts – Save a File Usage Differs on Windows and Windows Phone Windows Windows Phone //Create the picker object FileSavePicker savePicker = new FileSavePicker(); savePicker.SuggestedStartLocation = PickerLocationId.DocumentsLibrary; // Dropdown of file types the user can save the file as    savePicker.FileTypeChoices.Add( "Plain Text", new List<string>() { ".txt" }); // Default file name if the user does not type one in or select // a file to replace savePicker.SuggestedFileName = "New Document"; // Open the picker for the user to select the target file StorageFile file = await openPicker.PickSaveFileAsync(); // Save the content to the file ... //Create the picker object FileSavePicker savePicker = new FileSavePicker(); // Dropdown of file types the user can save the file as    savePicker.FileTypeChoices.Add( "Plain Text", new List<string>() { ".txt" }); // Default file name if the user does not type one in or select  // a file to replace savePicker.SuggestedFileName = "New Document"; // Open the picker for the user to pick a file savePicker.ContinuationData["Operation"] = "SomeDataOrOther"; savePicker.PickSingleFileAndContinue(); App suspended, may be terminated App activated when file picked © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

43 Using the picker contracts
demo

44 File Open/Save Picker Comparison with Windows
11/7/2018 File Open/Save Picker Comparison with Windows Different APIs on Windows 8.1 and Windows Phone 8.1 Resulting from requirement to support low memory devices Phone-specific behavior SuggestedStartLocation is ignored ViewMode is ignored FileNameChanged event is not fired Title is ignored © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

45 File Picker Provider apps
Similar to Share Target apps, you can create apps that will be listed in the shell Picker UI that the user can select to pick files that that app controls, or to save new files Example: OneDrive app is a picker provider that allows users to pick and save files in their OneDrive account in the cloud Available for Windows Runtime and Windows Phone Silverlight 8.1 See MSDN documentation for further details

46 Windows.Storage.AccessCache

47 11/7/2018 What is AccessCache? Imagine an app that uses the File pickers to open and save files at any location What if the user wants to reopen a file he or she edited last week? Do we need to show the picker and get the user to open the file again? We need a way to store references to files and folders and their permissions so that the user can reopen them with one tap That way is through Windows.Storage.AccessCache.StorageApplicationPermissions © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

48 FutureAccessList and MostRecentlyUsedList
11/7/2018 FutureAccessList and MostRecentlyUsedList All apps have a FutureAccessList and a MostRecentlyUsedList (MRU) The MRU is a list you can use to track the files and folders your user accesses frequently 25-item limit, automatically managed so oldest item automatically removed when limit is reached FutureAccessList is a list you can use to store files and/or locations (like folders) and easily access them in the future 1000-item limit, but not automatically managed, so you must remove items when limit is reached If File or Folder is later moved, FutureAccessList tracks it automatically, maintaining access in the future When a user picks a file or folder, you should consider adding that item to both the MRU and the FutureAccessList © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

49 Usage – Saving in the AccessCache
11/7/2018 Usage – Saving in the AccessCache public async void ContinueFileOpenPicker(FileOpenPickerContinuationEventArgs args) { if ((args.Files != null && args.Files.Count > 0) StorageFile file = args.Files[0]; // Save the picked file in the AccessCache // Add to MRU with metadata (For example, a string that represents the date) string mruToken = StorageApplicationPermissions.MostRecentlyUsedList.Add(file, " "); // Add to FA without metadata string faToken = StorageApplicationPermissions.FutureAccessList.Add(file); } else // The file picker was dismissed with no file selected to save © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

50 Usage – Retrieving from the Access Cache
11/7/2018 Usage – Retrieving from the Access Cache // get the token for the first item in our MRU and use it to retrieve a StorageFile that represents that file String mruFirstToken = StorageApplicationPermissions.MostRecentlyUsedList.Entries.First().Token; StorageFile retrievedFile = await StorageApplicationPermissions.MostRecentlyUsedList.GetFileAsync(mruFirstToken); ... // Retrieve tokens for all items in the MRU AccessListEntryView mruEntries = StorageApplicationPermissions.MostRecentlyUsedList.Entries; if (mruEntries.Count > 0) { foreach (AccessListEntry entry in mruEntries) String mruToken = entry.Token; // Continue processing the MRU entry } © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

51 Access cache demo

52 Summary

53 Adding it all up File associations Yes URI contracts Share Limited
11/7/2018 Adding it all up Windows Phone 8 Windows Phone 8.1 Windows 8.1 File associations Yes URI contracts Share Limited File open picker No File save picker © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

54 11/7/2018 New Possibilities © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

55


Download ppt "Sharing Files and Data in Windows Phone 8.1"

Similar presentations


Ads by Google