SlideShare a Scribd company logo
1 of 12
Download to read offline
Scoped Storage in Android 10- All You
Need to Know
Every Android version has something for developers and users alike. The
Android 10 version has many user-friendly features and performance
enhancements. For example, Android has introduced a new storage system in
Android 10 known as Scoped Storage. But before diving deep into this new
storage system and discussing its role in Android app development, let’s go
through the aspects of a current Shared Storage system.
• Brief on Shared Storage:
Before the advent of Scoped Storage, the shared storage had the following
characteristics for Android phone users-
• All apps have their private Directory in Internal Storage i.e android/data/your
package name, which is not visible to other apps.
• Most of the apps require broad storage permission to perform simple
functions. For example, downloading images or as image picker, etc. Now, at
the time of uninstalling apps, most of the app-related files don’t get deleted.
This results in the issue of insufficient storage.
Android 10 has brought a redesigned storage system to overcome these
issues. We know it as Scoped Storage.
• What is Scoped Storage?
• It’s a concept of storing files, images, etc separately called Collections which
restricts the conventional access of the whole storage.
• Better Attribution: This means which app created which file is known by the
system. It is useful when the App is uninstalled, so all the data related to the
app is also uninstalled.
• Protecting App Data: Internal app directories and external app directories are
private.
Protect user data: Downloaded image not to be used by another app.
Key Features:
1. Unrestricted access to its individual App storage(Internal / External): No
Permission Required.
2. Unrestricted Access to Media files and Download Collection: E.g Save
image file without Permission.
3. Only Media Collections can be read with Storage Permission.
4. Location MetaData ACCESS_MEDIA_LOCATION for the location of the
image.
5. For files like pdf, text, etc use System Picker.
6. Reading and writing outside of collection requires the “System Picker”.
Some New Flags
– when you insert an item that is marked as pending intent(value 1), by default
it will be hidden from other apps on the device. This can be used when you
use a long-running Download, eg. Video Downloading from URL.
– Once the download is completed, set the pending intent to 0, to reveal it to
other apps to the device
values.put(MediaStore.Images.Media.IS_PENDING,0)
resolver.update(item,null,null,null)
– In the above example, we have not set/specified the path to store the image,
so OS automatically chooses the path based on the file type. Here we took
image/jpeg, So it will store images to the Pictures folder by default.
You can also choose the File path by Media.RELATIVE_PATH
Eg.
val values = ContentValues().apply{
put(MediaStore.Images.Media.RELATIVE_PATH,”MYPICS”)
put(MediaStore.Images.Media.DISPLAY_NAME,”IMG.JPG”)
put(MediaStore.Images.Media.MIME_TYPE,”image/jpeg”)
put(MediaStore.Images.Media.IS_PENDING,1) }
– VOLUME_EXTERNAL_PRIMARY to store in primary Storage.
RequestLegacyAccess Tag
In the manifest file, we can still add to use the permission access like in the
lower version than Android 10. But only used by 2% of an android app, and
also going to be deprecated in the next version of Android.
– The manifest flag default value is true for apps designed to run on Android 9
(and lower versions).
– The default value is false for apps developed for Android 10.
ACCESS_MEDIA_LOCATION permission
– It is Runtime permission
– Used to get Location of image ie. Latitude and Longitude with EXIFInterface.
– Not visible in settings
– No guarantee you will have always have this permission, also if you have
READ_EXTERNAL_STORAGE permission
– To get the exact number of bytes of Files, Use
MediaStore.setRequiredOriginal() , if not success the exception occurs
Do/Don’ts For Storage
– Don’t Use a Static path. Locked down the file path access.
– Use MediaStore (recommend).
– Media Store should be used in a proper way, for example, Don’t put your
Music files in Picture directory.
– Non-media files should be in the Download directory(recommend).
To Modify and Delete Media
– User Consent required when edit or delete media
– Consent required even for file path access
– Bulk edit delete in same dialog(Next Release)
Special APP Access
– Only granted app that can prove the clear need to storage
– Submit declaration form to Google Play
– WhiteListed apps by Google
– No access to external app directories
Examples(Use Cases):
1. Media Player App
– Read all video files
– Mediastore API
– Content Resolver API
– READ_EXTERNAL_STORAGE required
2. Edit Image/Delete Image
– Media Store API
– READ_EXTERNAL_STORAGE
– Next Release -Bulk Delete in single dialog available
3. GMAIL file attach
– SAF
– NO Permission required
– UI is handled by intent
– To save file while sending you can use
ACTION_CRATE_DOCUMENT
How to Implement?
• Use ACTION_OPEN_DOCUMENT to select File.
• Use ACTION_OPEN_DOCUMENT_TREE to select a folder: This will ask for
permission in Android 10, for full access to that folder.
• Saving Image file using MediaStore API.
– Purpose of using IS_PENDING flag in MediaStore?
When you insert an item which is marked as pending intent(value 1), by
default it will be hidden from other apps on the device. This can be used when
you use long-running Downloads like Video Downloading from URL.
Once the download is completed, set the pending intent to 0, to reveal it to
other apps to the device.
• In the above example, we have not set/specified the path to store the image,
so OS automatically chooses the path based on file type. Here we took
image/jpeg, So it will store images to the Pictures folder by default.
• You can also choose the file path by Media.RELATIVE_PATH.
VOLUME_EXTERNAL_PRIMARY to store in primary Storage. And to get list
of storages available on the phone use
MediaStore.getExternalVolumeNames(context).
• Upon getting a document URI returned, we can use
it.[ContentResolver.takePersistableUriPermission] in order to persist the
permission across restarts.
• If your app uses scoped storage, raw file path access is limited to the app-
specific directories on external storage, even if your app has been granted
the READ_EXTERNAL_STORAGE permission. If your app attempts to use a
raw path to open a file within external storage, but it doesn’t reside in the app-
specific directory, then an exception called FileNotFoundException occurs.
For example, the path for a file outside the app-specific directory is
/sdcard/DCIM/ABC.JPG. Here, your app should use methods given in the
MediaStore API.
• In Android Q and above, it isn’t possible to modify or delete items in
MediaStore directly, and explicit permission must usually be obtained to do
this. Here, the OS will throw a RecoverableSecurityException that we can
catch here. Inside, we have an IntentSender that can be used by an activity to
prompt the user to grant permission to the item update or deletion.
Expected Changes in the Next Release
Permission UI Update: User will see a different Permission UI either based
on update and Scoped Storage or not i.e. before, 10 apps would see the
Board Access to storage and subsequent 10 apps will see media collection
access to storage.
- Enable File path and native libraries for reading media.
- Updating Media files and modifying APIS.
- Protecting External app Directories.
- Enforcement to target SDK.
- Read files not created by your app need READ_EXTRNAL_STORAGE
Permission.
- To edit and delete files not contributed by your app, then you need
explicit user concern.
- WRITE_EXTERNAL_STORAGE will be deprecated in the next Android
release and will give read permission only when used.
Non-Media File Access:
To Access non-media files by other apps, use System picker with
SAF(Storage Access Framework). Runtime permission will have been asked
for complete access to that app.
Things To Remember: If Android 10 is within the scope of your application,
kindly use MediaStore/SystemPicker for File and Documents access.

More Related Content

Similar to Scoped storage in android 10 all you need to know

Android File Management Presentation.pptx
Android File Management Presentation.pptxAndroid File Management Presentation.pptx
Android File Management Presentation.pptxvuqaxuly
 
Android File Management Presentation.pptx
Android File Management Presentation.pptxAndroid File Management Presentation.pptx
Android File Management Presentation.pptxvuqaxuly
 
Android development-tutorial
Android development-tutorialAndroid development-tutorial
Android development-tutorialnirajsimulanis
 
File system in iOS
File system in iOSFile system in iOS
File system in iOSPurvik Rana
 
Introduction to android
Introduction to androidIntroduction to android
Introduction to androidjavalabsf
 
Android tutorial
Android tutorialAndroid tutorial
Android tutorialmaster760
 
Dreamwares Recent Projects
Dreamwares Recent ProjectsDreamwares Recent Projects
Dreamwares Recent ProjectsDreamwares
 
important DotNet Questions For Practicals And Interviews
important DotNet Questions For Practicals And Interviewsimportant DotNet Questions For Practicals And Interviews
important DotNet Questions For Practicals And InterviewsRahul Jain
 
Introduction to Android and Java.pptx
Introduction to Android and Java.pptxIntroduction to Android and Java.pptx
Introduction to Android and Java.pptxGandhiMathy6
 
Mobile Application Development -Lecture 11 & 12.pdf
Mobile Application Development -Lecture 11 & 12.pdfMobile Application Development -Lecture 11 & 12.pdf
Mobile Application Development -Lecture 11 & 12.pdfAbdullahMunir32
 
Android application structure
Android application structureAndroid application structure
Android application structureAlexey Ustenko
 
Google android white paper
Google android white paperGoogle android white paper
Google android white paperSravan Reddy
 
Mediating Applications on the Android System
Mediating Applications on the Android SystemMediating Applications on the Android System
Mediating Applications on the Android SystemNizar Maan
 

Similar to Scoped storage in android 10 all you need to know (20)

Mobile testing android
Mobile testing   androidMobile testing   android
Mobile testing android
 
Apps rollback patches1
Apps rollback patches1Apps rollback patches1
Apps rollback patches1
 
Lesson 10
Lesson 10Lesson 10
Lesson 10
 
Android File Management Presentation.pptx
Android File Management Presentation.pptxAndroid File Management Presentation.pptx
Android File Management Presentation.pptx
 
Android File Management Presentation.pptx
Android File Management Presentation.pptxAndroid File Management Presentation.pptx
Android File Management Presentation.pptx
 
Android development-tutorial
Android development-tutorialAndroid development-tutorial
Android development-tutorial
 
Imd 113
Imd 113Imd 113
Imd 113
 
File system in iOS
File system in iOSFile system in iOS
File system in iOS
 
Introduction to android
Introduction to androidIntroduction to android
Introduction to android
 
Android Basic- CMC
Android Basic- CMCAndroid Basic- CMC
Android Basic- CMC
 
Android tutorial
Android tutorialAndroid tutorial
Android tutorial
 
Dreamwares Recent Projects
Dreamwares Recent ProjectsDreamwares Recent Projects
Dreamwares Recent Projects
 
important DotNet Questions For Practicals And Interviews
important DotNet Questions For Practicals And Interviewsimportant DotNet Questions For Practicals And Interviews
important DotNet Questions For Practicals And Interviews
 
Ten Myths About Deleted Files
Ten Myths About Deleted FilesTen Myths About Deleted Files
Ten Myths About Deleted Files
 
Ten Myths About Recovery Deleted Files
Ten Myths About Recovery Deleted FilesTen Myths About Recovery Deleted Files
Ten Myths About Recovery Deleted Files
 
Introduction to Android and Java.pptx
Introduction to Android and Java.pptxIntroduction to Android and Java.pptx
Introduction to Android and Java.pptx
 
Mobile Application Development -Lecture 11 & 12.pdf
Mobile Application Development -Lecture 11 & 12.pdfMobile Application Development -Lecture 11 & 12.pdf
Mobile Application Development -Lecture 11 & 12.pdf
 
Android application structure
Android application structureAndroid application structure
Android application structure
 
Google android white paper
Google android white paperGoogle android white paper
Google android white paper
 
Mediating Applications on the Android System
Mediating Applications on the Android SystemMediating Applications on the Android System
Mediating Applications on the Android System
 

Recently uploaded

Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 

Recently uploaded (20)

Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort ServiceHot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 

Scoped storage in android 10 all you need to know

  • 1. Scoped Storage in Android 10- All You Need to Know Every Android version has something for developers and users alike. The Android 10 version has many user-friendly features and performance enhancements. For example, Android has introduced a new storage system in Android 10 known as Scoped Storage. But before diving deep into this new storage system and discussing its role in Android app development, let’s go through the aspects of a current Shared Storage system. • Brief on Shared Storage: Before the advent of Scoped Storage, the shared storage had the following characteristics for Android phone users- • All apps have their private Directory in Internal Storage i.e android/data/your package name, which is not visible to other apps. • Most of the apps require broad storage permission to perform simple functions. For example, downloading images or as image picker, etc. Now, at
  • 2. the time of uninstalling apps, most of the app-related files don’t get deleted. This results in the issue of insufficient storage. Android 10 has brought a redesigned storage system to overcome these issues. We know it as Scoped Storage. • What is Scoped Storage? • It’s a concept of storing files, images, etc separately called Collections which restricts the conventional access of the whole storage. • Better Attribution: This means which app created which file is known by the system. It is useful when the App is uninstalled, so all the data related to the app is also uninstalled. • Protecting App Data: Internal app directories and external app directories are private. Protect user data: Downloaded image not to be used by another app. Key Features: 1. Unrestricted access to its individual App storage(Internal / External): No Permission Required. 2. Unrestricted Access to Media files and Download Collection: E.g Save image file without Permission. 3. Only Media Collections can be read with Storage Permission. 4. Location MetaData ACCESS_MEDIA_LOCATION for the location of the image. 5. For files like pdf, text, etc use System Picker. 6. Reading and writing outside of collection requires the “System Picker”.
  • 3. Some New Flags – when you insert an item that is marked as pending intent(value 1), by default it will be hidden from other apps on the device. This can be used when you use a long-running Download, eg. Video Downloading from URL. – Once the download is completed, set the pending intent to 0, to reveal it to other apps to the device values.put(MediaStore.Images.Media.IS_PENDING,0) resolver.update(item,null,null,null) – In the above example, we have not set/specified the path to store the image, so OS automatically chooses the path based on the file type. Here we took image/jpeg, So it will store images to the Pictures folder by default. You can also choose the File path by Media.RELATIVE_PATH Eg. val values = ContentValues().apply{ put(MediaStore.Images.Media.RELATIVE_PATH,”MYPICS”) put(MediaStore.Images.Media.DISPLAY_NAME,”IMG.JPG”) put(MediaStore.Images.Media.MIME_TYPE,”image/jpeg”) put(MediaStore.Images.Media.IS_PENDING,1) } – VOLUME_EXTERNAL_PRIMARY to store in primary Storage.
  • 4. RequestLegacyAccess Tag In the manifest file, we can still add to use the permission access like in the lower version than Android 10. But only used by 2% of an android app, and also going to be deprecated in the next version of Android. – The manifest flag default value is true for apps designed to run on Android 9 (and lower versions). – The default value is false for apps developed for Android 10. ACCESS_MEDIA_LOCATION permission – It is Runtime permission – Used to get Location of image ie. Latitude and Longitude with EXIFInterface. – Not visible in settings – No guarantee you will have always have this permission, also if you have READ_EXTERNAL_STORAGE permission – To get the exact number of bytes of Files, Use MediaStore.setRequiredOriginal() , if not success the exception occurs Do/Don’ts For Storage – Don’t Use a Static path. Locked down the file path access. – Use MediaStore (recommend). – Media Store should be used in a proper way, for example, Don’t put your
  • 5. Music files in Picture directory. – Non-media files should be in the Download directory(recommend). To Modify and Delete Media – User Consent required when edit or delete media – Consent required even for file path access – Bulk edit delete in same dialog(Next Release) Special APP Access – Only granted app that can prove the clear need to storage – Submit declaration form to Google Play – WhiteListed apps by Google – No access to external app directories Examples(Use Cases): 1. Media Player App – Read all video files – Mediastore API – Content Resolver API – READ_EXTERNAL_STORAGE required 2. Edit Image/Delete Image – Media Store API – READ_EXTERNAL_STORAGE – Next Release -Bulk Delete in single dialog available 3. GMAIL file attach – SAF – NO Permission required – UI is handled by intent – To save file while sending you can use ACTION_CRATE_DOCUMENT
  • 6. How to Implement? • Use ACTION_OPEN_DOCUMENT to select File. • Use ACTION_OPEN_DOCUMENT_TREE to select a folder: This will ask for permission in Android 10, for full access to that folder.
  • 7. • Saving Image file using MediaStore API. – Purpose of using IS_PENDING flag in MediaStore?
  • 8.
  • 9. When you insert an item which is marked as pending intent(value 1), by default it will be hidden from other apps on the device. This can be used when you use long-running Downloads like Video Downloading from URL. Once the download is completed, set the pending intent to 0, to reveal it to other apps to the device. • In the above example, we have not set/specified the path to store the image, so OS automatically chooses the path based on file type. Here we took image/jpeg, So it will store images to the Pictures folder by default. • You can also choose the file path by Media.RELATIVE_PATH. VOLUME_EXTERNAL_PRIMARY to store in primary Storage. And to get list of storages available on the phone use MediaStore.getExternalVolumeNames(context). • Upon getting a document URI returned, we can use it.[ContentResolver.takePersistableUriPermission] in order to persist the permission across restarts. • If your app uses scoped storage, raw file path access is limited to the app- specific directories on external storage, even if your app has been granted the READ_EXTERNAL_STORAGE permission. If your app attempts to use a raw path to open a file within external storage, but it doesn’t reside in the app- specific directory, then an exception called FileNotFoundException occurs.
  • 10. For example, the path for a file outside the app-specific directory is /sdcard/DCIM/ABC.JPG. Here, your app should use methods given in the MediaStore API. • In Android Q and above, it isn’t possible to modify or delete items in MediaStore directly, and explicit permission must usually be obtained to do this. Here, the OS will throw a RecoverableSecurityException that we can catch here. Inside, we have an IntentSender that can be used by an activity to prompt the user to grant permission to the item update or deletion.
  • 11. Expected Changes in the Next Release Permission UI Update: User will see a different Permission UI either based on update and Scoped Storage or not i.e. before, 10 apps would see the Board Access to storage and subsequent 10 apps will see media collection access to storage. - Enable File path and native libraries for reading media. - Updating Media files and modifying APIS. - Protecting External app Directories. - Enforcement to target SDK.
  • 12. - Read files not created by your app need READ_EXTRNAL_STORAGE Permission. - To edit and delete files not contributed by your app, then you need explicit user concern. - WRITE_EXTERNAL_STORAGE will be deprecated in the next Android release and will give read permission only when used. Non-Media File Access: To Access non-media files by other apps, use System picker with SAF(Storage Access Framework). Runtime permission will have been asked for complete access to that app. Things To Remember: If Android 10 is within the scope of your application, kindly use MediaStore/SystemPicker for File and Documents access.