Windows 10 - App to App communication in Universal Windows Applications

Windows 10 provides many techniques that developers can use for inter- app communications. Publisher Cache Folders is one such technique. The idea is that A publisher can have multiple applications in Windows Store and they may share common data , settings and other artifacts that could be leveraged across multiple applications.

While using Publisher Cache Folders in your application , here are few things to keep in mind

-The apps reading/writing or using Publisher Cache Folders needs to be from same publisher.

-Shared storage location is provisioned automatically when the first app for a given publisher is installed and it will be removed automatically when the last app for a given publisher is uninstalled

-You are responsible for data management /versioning inside the Publisher Cache Folder.

-Publisher Cache folder can also live in a SD card

Implementing Publisher Cache Folders is really easy. In following example I have implemented a simple read write on a text file that is living inside Publisher Cache Folders from 2 different applications.

As a first step we will declare the Publisher Cache Folder in the application manifest of each application wanting to use the folder.

 <Extensions> <Extension Category="windows.publisherCacheFolders"> <PublisherCacheFolders > <Folder Name="CommonFolder"/> </PublisherCacheFolders> </Extension> 

 

Now folder is available for us to be utilized from different applications. Writing to the folder from App1

  async void WritetoPublisherFolder() { StorageFolder SharedFolder = Windows.Storage.ApplicationData.Current.GetPublisherCacheFolder("CommonFolder"); StorageFile newFile = await SharedFolder.CreateFileAsync("SharedFile.txt", CreationCollisionOption.OpenIfExists); await FileIO.WriteTextAsync(newFile, textBox.Text.ToString()); } 

Reading from Folder from App2

  async void ReadFromSharedFolder() { StorageFolder SharedFolder = Windows.Storage.ApplicationData.Current.GetPublisherCacheFolder("CommonFolder"); StorageFile newFile = await SharedFolder.GetFileAsync("SharedFile.txt"); var text= await FileIO.ReadTextAsync(newFile); textBlock.Text= await FileIO.ReadTextAsync(newFile); ; } 

Publisher Cache Folders opens up many scenarios for the developers building multiple applications and sharing the data among those applications.