Android N’s Packs Storage Access Framework Allows Virtual Files While Locally Unavailable

N has one more hidden feature in the latest Android N Developer Preview 3. The latest and the greatest Android N build have Sustained performance mode and 48 other features on the changelog.

In addition to them, there’s one more feature and that is Storage Access Framework. It allows Android N to make files available virtually if those are not available there. SAF was available earlier also but Virtual files function was missing at that time.

Recently, Dropbox quoted that they are coming with similar functionality on their cloud services.

Virtual files are effectively placeholders for the real file. THese files does not contain any memory much more that the actual placeholder size. These files are retrieved upon the usage. In previous versions of Android, your app could use the Storage Access Framework to allow users to select files from their cloud storage accounts, such as Google Drive. However, there was no way to represent files that did not have a direct bytecode representation; every file was required to provide an input stream.

Android N adds the concept of virtual files to the Storage Access Framework. The virtual files feature allows your DocumentsProvider to return document URIs that can be used with anACTION_VIEW intent even if they don’t have a direct bytecode representation. Android N also allows you to provide alternate formats for user files, virtual or otherwise.

To get a URI for a virtual document in your app, first you create an Intent to open the file picker UI. Since an app cannot directly open a virtual file by using the openInputStream()method, your app does not receive any virtual files if you include the CATEGORY_OPENABLEcategory.

After the user has made a selection, the system calls the onActivityResult() method. Your app can retrieve the URI of the virtual file and get an input stream, as demonstrated in the code snippet below.

Previous articlePre-orders for LG G5 will Start on May 21 in India
Next articleSeamless Update Feature Not Coming To Present Nexus Devices
Simranpal Singh
With a decade-long journey in the tech industry, I've been actively engaged in tech reporting across various reputable publications. He currently works as a Web Developer at RightNode Media and pursues his hobby of writing on GoAndroid. Enjoy travelling, and always excited about new tech trends. He actively contributes on GizmoChina and GChromecast Hub.


Please enter your comment!
Please enter your name here