<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Sanjay Prajapati on Medium]]></title>
        <description><![CDATA[Stories by Sanjay Prajapati on Medium]]></description>
        <link>https://medium.com/@sanjay_prajapati?source=rss-ec29102c6bc6------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*1x-GcA3IWbhrZyZfMhIGoA.jpeg</url>
            <title>Stories by Sanjay Prajapati on Medium</title>
            <link>https://medium.com/@sanjay_prajapati?source=rss-ec29102c6bc6------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 17:12:02 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@sanjay_prajapati/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Understanding Scoped Storage in Android]]></title>
            <link>https://medium.com/mindful-engineering/scoped-storage-in-android-d52460630d6a?source=rss-ec29102c6bc6------2</link>
            <guid isPermaLink="false">https://medium.com/p/d52460630d6a</guid>
            <category><![CDATA[android-11]]></category>
            <category><![CDATA[android-10]]></category>
            <category><![CDATA[scoped-storage]]></category>
            <category><![CDATA[android-storage]]></category>
            <category><![CDATA[android]]></category>
            <dc:creator><![CDATA[Sanjay Prajapati]]></dc:creator>
            <pubDate>Fri, 11 Jun 2021 12:46:49 GMT</pubDate>
            <atom:updated>2021-06-11T14:07:26.536Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EXMsrxKRTotly-lcjE7Nxg.jpeg" /><figcaption>photo on <a href="https://images.app.goo.gl/sNhGTYnoDykxxWoa7">Flipboard</a></figcaption></figure><p>Scope storage introduced in Android 10. The idea of organizing shared storage into the specific collection and limit access to broad storage.</p><p><strong>Changes introduced with scope storage:</strong></p><ol><li>Apps have unrestricted access to your app storage (internal memory and external volume).</li><li>Shared storage is divided into 4 organized collections: Pictures, Videos, Music &amp; Downloads. Apps can contribute to this organized collection without any permission.</li><li>Storage Runtime permission that only gives read access to shared Pictures, Videos &amp; Music files. To access downloads and unorganized files user must give specific access via the document picker.</li><li>The modifying media files which are not created by your app will require user confirmation.</li><li>New permission for photo’s location metadata</li></ol><h3><strong>Why requestLegacyExternalStorage flag introduced in Android 10?</strong></h3><p>Many apps successfully migrated to scope storage on android 10 but recognized that some of the apps didn’t sufficiently satisfy all of the use cases in that release so, to opt-out from scope storage, we have to set the <strong>requestLegacyExternalStorage</strong> flag in the android manifest file.</p><pre>&lt;manifest ... &gt;<br>  &lt;!-- This attribute is &quot;false&quot; by default on apps targeting<br>       Android 10. --&gt;<br>  &lt;application android:requestLegacyExternalStorage=&quot;true&quot; ... &gt;<br>    ...<br>  &lt;/application&gt;<br>&lt;/manifest&gt;</pre><p>Based on the scope storage update google received updates from all kinds of developers that scope storage change isn’t easy for many applications. For that, some of the improvements were introduced in Android 11 so that makes the transition easier. Because of these changes, they made it compulsory for all the apps which target Android 11. There is no option to opt out.</p><p>The above <strong>requestLegacyExternalStorage</strong> flag will not work if you target your app to Android 11.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/498/1*kjNA8cE4WXC5U60qiL6D-w.gif" /><figcaption>Photo on <a href="https://media1.tenor.com/images/def2f82ca7ea4913e68c47944291bf5d/tenor.gif?itemid=15218644">tenor</a></figcaption></figure><h3><strong>Here are new features in Android 11</strong></h3><ol><li><strong>Enabled File Path APIs.</strong> As turn it to MediaStore APIs, the apps can choose other APIs which rely on the local file paths. This is likely to reduce or eliminate the line of code you have to change while upgrading to target Android 11.</li><li><strong>Bulk media modification APIs.</strong> They have created new easier to use APIs for modifying media files and edit the ability to make changes in bulk.</li><li><strong>All Files Access</strong>. For specific apps that they can require the ability to read more broadly, they created new special app access called All Files Access.</li><li><strong>Private app storage</strong>. App storage is now private from another app including an external directory.</li></ol><p>Let us go with the details of each topic</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*yDUjzWioS5wnvO1EJE6kyw.gif" /><figcaption>Photo on <a href="https://media1.tenor.com/images/59558f0cb20a9c713c2a7559a1ec1eb6/tenor.gif?itemid=4383603">tenor</a></figcaption></figure><p><strong>Using File Paths:</strong></p><ul><li>File Path API is an alternative to MediaStore APIs.</li><li>Refactoring entire applications and libraries that used file paths for various operations can take several months or even years. To make things worse, some native libraries likely no longer have support. To overcome this, they updated the <strong>File API</strong> that allows you to continue using Java Files APIs or native C/C++ libraries with scoped storage without the need to make more changes. The file path access is delegated to the MediaStore API, which will handle all the operations.</li><li>With scope storage enabled on Android 10 apps were only able to access shared files using MediaStore APIs. A collection of APIs specifically designed for working with index files in shared storage. These APIs identify files using file descriptors rather than local file paths. MediaStore is an efficient and useful set of APIs, so this is the best solution for working with shared files for most of the app.</li><li>Disallowing API to use the file path like java Files APIs, Native libraries(C, C++) cause significant compatibility issues between Android Pi and Android 10.</li><li>Compatibility is important for each Android release so easily that developers can take advantage of each new Android release. So they decided the best thing they can do to help developers migrate scope storage. That defines them to allow the way to use File path APIs while keeping the new privacy requirements.</li><li>By leveraging a few, files system and user-space they reenable these APIs for scope storage. For example, now apps can successfully use FFMpeg (Fast-forward MPEG), a free and open-source multimedia framework that can decode, encode, transcode, mux, demux, stream, filter, and play fairly all kinds of multimedia files that have been created to date) multimedia framework.</li><li>You can think of File Path APIs in Android 11 as convenient APIs to the MediaStore.</li><li>You do not get any additional access to a file you would have gotten by using MediaStore APIs. This is a different way to implement your application functionality if you choose to.</li><li>You can get the file path of the file MediaStore by looking into the DATA column because the file path API is now directly linked to MediaStore APIs. Anytime you create a new file such as save a new photo using a file path API it will be immediately added to MediaStore. This is helpful because then there is never delay. As there might be an older version of Android between contributing files to shared storage another app’s ability to access them. However, these cuts cause some unexpected behavior if your application previously operating under the assumption that the new file will not be indexed right away. So keep this in your mind as you test your app on Android 11.</li></ul><p><strong>Bulk Media Modification</strong></p><ul><li>As a part of android scope storage in the Android 11 release, they introduced a new requirement in which the app needs to get user consent to perform modifying or deleting the file does not own.</li><li>For Android 11 they created new easier to use APIs to get these consents. <a href="https://developer.android.com/reference/android/provider/MediaStore#createWriteRequest(android.content.ContentResolver,%20java.util.Collection%3Candroid.net.Uri%3E)">createWriteRequest</a>, <a href="https://developer.android.com/reference/android/provider/MediaStore#createDeleteRequest(android.content.ContentResolver,%20java.util.Collection%3Candroid.net.Uri%3E)">createDeleteRequest</a>.</li><li>For example, here is how to structure a call to createWriteRequest()</li></ul><pre>val urisToModify = /* A collection of content URIs to modify. */<br>val editPendingIntent = MediaStore.createWriteRequest(contentResolver,<br>        urisToModify)<br><br>// Launch a system prompt requesting user permission for the operation.<br>startIntentSenderForResult(editPendingIntent.intentSender, EDIT_REQUEST_CODE,<br>    null, 0, 0, 0)</pre><p>If the user provided consent, proceed with the media operation. Otherwise, explain to the user why your app needs the permission:</p><pre>override fun onActivityResult(requestCode: Int, resultCode: Int,<br>                 data: Intent?) {<br>    ...<br>    when (requestCode) {<br>        EDIT_REQUEST_CODE -&gt;<br>            if (resultCode == Activity.RESULT_OK) {<br>                /* Edit request granted; proceed. */<br>            } else {<br>                /* Edit request not granted; explain to the user. */<br>            }<br>    }<br>}</pre><ul><li>Using both the request, apps can request consent from modifying several media files at once. If you already own the file and want to modify it, you don’t need to request user consent.</li><li>You can use this same general pattern with <a href="https://developer.android.com/reference/android/provider/MediaStore#createFavoriteRequest(android.content.ContentResolver,%20java.util.Collection%3Candroid.net.Uri%3E,%20boolean)"><strong>createFavoriteRequest()</strong></a><strong>, </strong><a href="https://developer.android.com/reference/android/provider/MediaStore#createTrashRequest(android.content.ContentResolver,%20java.util.Collection%3Candroid.net.Uri%3E,%20boolean)"><strong>createTrashRequest()</strong></a><strong>, and </strong><a href="https://developer.android.com/reference/android/provider/MediaStore#createDeleteRequest(android.content.ContentResolver,%20java.util.Collection%3Candroid.net.Uri%3E)"><strong>createDeleteRequest()</strong></a></li><li>They created a new media concept for Trash(<a href="https://developer.android.com/reference/android/provider/MediaStore#createTrashRequest(android.content.ContentResolver,%20java.util.Collection%3Candroid.net.Uri%3E,%20boolean)">createTrashRequest()</a>) that behaves like a recycle bin in a computer. The app can now choose to trash files instead of deleting them. This can give the user a chance to recover the file later. Trash files will be hidden by default but that can be displayed if an app wants to. A trash item will be automatically deleted by the OS after 30 days. Trash files can be untrash at any time before expiration by an app that earlier access to it or with user consents.</li><li>They also created new file status called favorite (<a href="https://developer.android.com/reference/android/provider/MediaStore#createFavoriteRequest(android.content.ContentResolver,%20java.util.Collection%3Candroid.net.Uri%3E,%20boolean)">createFavoriteRequest()</a>). for example, in your gallery app, you may be custom to storing a photo you like so you can find it more easily. Now, this can work across apps. If your app has a user experience of picking from all available photos you can now choose favorited photos first or highlight them differently.</li><li>Similarly to modifying files apps must get user consent before trashing and favoriting files which it does own. However, the default gallery app on the device will never be required to prompt the user’s for any modification.</li></ul><p><strong>All Files Access</strong></p><ul><li>Most apps that work with shared files will have everything they need with the READ_EXTERNAL_STORAGE permission which grants access to photos, videos, and music.</li><li>Apps like PDF readers and document readers can use to Storage Access Framework to request access to specific documents and downloads.</li><li>However, some apps require access to read and write permissions for all files and shared storage to carry out the primary purpose. Some apps are file managers and backup apps. Apps like these which users rely on to move and modify all kinds of files now have the option to request the new permission called ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION or MANAGE_EXTERNAL_STORAGE in code.</li><li>MANAGE_EXTERNAL_STORAGE grants write access to all files except those in foreign app directories because this is quite sensitive it’s not run time permission but instead special app access.</li><li>Declare the following permission in <strong>AndroidManifest.xml</strong>:</li></ul><pre>&lt;uses-permission android:name=&quot;android.permission.MANAGE_EXTERNAL_STORAGE&quot;/&gt;</pre><p>As a security measure, adding this permission isn’t enough; the user still needs to manually grant access to the app. Call:</p><pre>fun openSettingsAllFilesAccess(activity: AppCompatActivity) {<br>  val intent = Intent(Settings.ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION)<br>  activity.startActivity(intent)<br>}</pre><p>This opens the native settings screen in the “All files access” section, which lists all the apps allowed to access the entire file system. The user needs to select both the app and the “Allowed” option to grant this access.</p><ul><li>Apps that request <a href="https://developer.android.com/about/versions/11/privacy/storage#all-files-access">ALL FILES access</a> and publish to google play will need to be verified manually to ensure they have a legitimate purpose to request it. For more details, you can check the <a href="https://support.google.com/googleplay/android-developer/answer/10467955?visit_id=637580508102832832-986713840&amp;rd=1#zippy=%2Cpermitted-uses-of-the-all-files-access-permission">link</a>. This protects users from inadequately granting overreaching access to an app that might be malicious.</li></ul><p><strong>Private App Storage</strong></p><ul><li>It’s never been best practice to directly access files saved in another app’s external storage directory. The best way for an app to share files by using share storage or content providers.</li><li>To formalize this on android 11 no app will be able to access another app’s external app storage. This includes all methods of reading files MediaStore, File Path APIs, and Storage Access Framework.</li><li>This is the one storage change that’s not gated on target android SDK. So if your app is accessing another app’s data or you are allowing apps to access your storage you will need to update to one of the approved methods to run as expected on Android R.</li></ul><h3><strong>Privacy changes for scoped storage</strong></h3><p>Scope storage changes related to privacy that are taking effect in Android 11.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/812/1*RQBnhZ4T5cOM9-0aEcUGXg.png" /><figcaption>Image from Android developers official document</figcaption></figure><h3><strong>Tips to Migrating</strong></h3><ul><li>If your app will be using file paths or All Files Access you will need to keep the legacy storage flag in your app manifest file this is to ensure compatibility with users running your app on Android 10.</li><li>If your app has a custom picking experience for non-media files like documents, you should use Storage Access Framework instead. This is not required for any permission.</li><li>Remember now modifying or deleting media files is not own requires user’s consent. So, use the new media storage consent API.</li><li>It is no longer advisable for your app to save files in a custom top-level directory. Doing so requires a Storage Access Framework which is not the best experience for users. If your app is un-install and reinstall then it will lose access to those files. They suggest using organized media collections or private app storage instead. If you use a top-level directory today you should migrate those files before upgrading your app.</li><li>If you wanna share data with other specific apps then set up content providers. This is the most secure way to share files.</li></ul><p>I hope this blog will help you to understand the scope storage related changes. For more details, you can check the <a href="https://developer.android.com/about/versions/11/privacy/storage">official document</a>.</p><p><strong>Happy Coding…!!!</strong>😊😊</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d52460630d6a" width="1" height="1" alt=""><hr><p><a href="https://medium.com/mindful-engineering/scoped-storage-in-android-d52460630d6a">Understanding Scoped Storage in Android</a> was originally published in <a href="https://medium.com/mindful-engineering">Mindful Engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>