title: Migrating a Flutter android (API 29) app's downloaded media(images, videos, PDF) to confirm to Scoped Storage of Android 11 (API Level 30)
body: <p>We have a flutter app similar to Whatsapp (say <strong>MessagingApp</strong>) for broadcasting messages with media (images, videos, PDF) within a closed group of people.</p>
  <p>The current flutter app's android <strong>targetSdkVersion is 29</strong> and uses the <strong>Legacy Storage</strong> using file path access method to read and write media files as described below.</p>
  <p>All the app's media files are downloaded under the base directory <code>/storage/emulated/0/MessagingApp</code>.</p>
  <p>Following are the example file path's of various media:</p>
  <p>Sample Downloaded Image's path <code>/storage/emulated/0/MessagingApp/MessagingApp_Images/20210410_111512.jpg</code></p>
  <p>Sample Downloaded Video's path <code>/storage/emulated/0/MessagingApp/MessagingApp_Videos/20210410_111513.mp4</code></p>
  <p>Sample Downloaded PDF's path <code>/storage/emulated/0/MessagingApp/MessagingApp_Documents/20210410_11151.pdf</code></p>
  <p>To download an image the <a href="https://pub.dev/packages/dio" rel="nofollow noreferrer">dio</a> package is used:</p>
  <p><code>dio.download(imageHttpUrl, '/storage/emulated/0/MessagingApp/MessagingApp_Images/20210410_111512.jpg',)</code></p>
  <p>The downloaded image is rendered in the app using the <code>Image.file</code> widget:
  <code>Image.file(File('/storage/emulated/0/MessagingApp/MessagingApp_Images/20210410_111512.jpg'))</code></p>
  <p><strong>The downloaded images can be viewed from android's Gallery app.</strong></p>
  <p>Starting November 2021, Playstore forces the targetSdkVersion to be 30 and in the API Level 30's Scoped Storage model, apps cannot create folders directly in the &quot;Shared Storage&quot;.</p>
  <p>In Scoped Storage the files can be downloaded and used from the app specific directory - <code>/storage/emulated/0/Android/data/org.test.MessagingApp/files</code>
  But they will not accessible to other(Gallery) apps.</p>
  <p>Other than that Scoped Storage mentions to use &quot;MediaStoreAPI&quot; for managing media.</p>
  <p>How to manage and handle downloaded media in Flutter android (API 30) with the new Scoped Storage of Android 11?</p>
  <p>Also i noticed on emulator running android 11 and app with targetSdkVersion 30, the app cannot create a folder in the root storage <code>/storage/emulated/0/</code>, but the android folders &quot;Documents, Download, DCIM, Pictures and so on&quot; are freely accesible, that is new folders can be created under them using the existing code i.e. the image path can be changed to <code>/storage/emulated/0/Documents/MessagingApp/MessagingApp_Images/20210410_111512.jpg</code> and it works.</p>
  <p>What is the best practice for using the new Scoped Storage of Android 11 for a Flutter android app?</p>