How to change storage access on Android 6?

Background

Android has had many changes regarding how to handle the SD card and storage in general:

  • API 3 - you get access, no permission required
  • API 4-15 - you need to use WRITE_EXTERNAL_STORAGE and you will get access.
  • API 16-18 - if you only want to read, use READ_EXTERNAL_STORAGE
  • API 19-20 - you cannot read or write to secondary external storage (SD card) if your application is not a system application or you have root.
  • API 21-22 - to access the SD card, you need to ask the user for permission and use the DocumentFile API instead of the File API. This caused a lot of questions as I wrote about here , here and here .

Starting with API 23 (Android 6), it looks like everything is changing again ...

Problem

For API 23, there are at least 2 things that are new and related to memory:

  • " Authenticated storage devices . The user can optionally make the SD card a bit of primary external storage."
  • As part of the new permissions mechanism (requesting runtime permissions), it looks like the repository is also a permission that the user must confirm. This is for READ_EXTERNAL_STORAGE and WRITE_EXTERNAL_STORAGE

Since Android does not have a device with an SD card, and since the emulator itself really does not have the ability to use an SD card, it is still impossible to find out what is happening.

Questions

  • Will the SD card be accessed using the File-API instead of the DocumentFile?

  • If I need access to all external storage paths (including the SD card), does this mean that I need to request these permissions twice: one for the main external storage and one for the SD card?

  • Are files on the SD card accessible in any way before being granted permission to use it manually?

  • Suppose a user decides to use "Adoptable Storage Devices", what does this mean for various functions that retrieve application file paths? For example: getFilesDir, getExternalFilesDir, ...? Would the other of getExternalFilesDirs change because of this?

  • What happens to application files when a user moves an application from / to an SD card (using "Adoptable Storage Devices")? What about application files on an SD card? Will they stay? Or will they move somewhere?

    For example, if the application has the file "file1.txt" on the SD card, on the path "/ storage / extSdCard / Android / data / appPackageName", and it has the file "file2.txt" (or even the same name) on the main external storage along the path "/ storage / emulated / 0 / Android / data / appPackageName". After switching, what will happen to these files? How would they merge into one folder, if at all?

  • When moving the application to the SD card (using "Adoptable Storage Devices"), does this mean that the internal storage will not be used?

+43
android android-6.0-marshmallow android-permissions android-externalstorage sd-card
Aug 20 '15 at 10:50
source share
1 answer

Let me answer Certified Storage Devices :

  1. Suppose a user decides to use "Adoptable Storage Devices", what does this mean for the various functions that retrieve application file paths? For example: getFilesDir, getExternalFilesDir, ...? Will the other of getExternalFilesDirs change because of this?

When the user chooses to use the SD card as an “Adoptable Storage Device” (format as internal), now this means that the SD card is only available as internal storage, that is, there is no SD card available to store downloaded files. Path changes in paths returned by related methods will not. For example: getExternalFilesDir () will only display the external storage path if the user has formatted their SD card as "Adoptable Storage Devices". The path to the SD card will not be available.

  1. What happens to application files when a user moves an application from / to an SD card (using "Adoptable Storage Devices")? What about application files on an SD card? Will they stay? Or are they moving somewhere? For example, if the application has the file "file1.txt" on the SD card, go to "/ storage / extSdCard / Android / data / appPackageName" and it has the file "file2.txt" (or even the same name) on primary external storage on the path "/ Storage / emulate / 0 / Android / data / appPackageName". After switching, what will happen to these files? How would they merge into one folder, if at all?

When the user selects their SD card as “Adoptable Storage Devices”, the user needs to format the SD card as internal storage using “Format as Internal” . Format means that all data / files stored on the SD card will be deleted. Similarly, when a user wants to remove his SD card from "Adoptable Storage Devices", the user again needs to format his SD card as portable storage using the "Format as portable" option.

  1. When moving the application to the SD card (using "Adoptable Storage Devices"), does this mean that the internal memory will not be used?

Yes, the original internal storage will not be used. Only SD card storage will be used, since after selecting the SD card as "Adoptable Storage Devices". All data / cache will be saved on the SD card.

+10
Aug 26 '15 at 5:04 on
source share



All Articles