Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
166 views
in Technique[技术] by (71.8m points)

sd card - How does storage access change on Android 6?

Background

Android had a lot of changes as to how to handle the SD-card and storage in general:

  • API 3 - you get all access, no permission needed
  • API 4-15 - you need to use WRITE_EXTERNAL_STORAGE, and you get all access.
  • API 16-18 - if you wish only to read, use READ_EXTERNAL_STORAGE
  • API 19-20 - you can't read or write to secondary external storage (SD-card), unless your app is a system app, or you have root.
  • API 21-22 - in order to access the SD-card, you need to ask the user for permission, and use the DocumentFile API instead of the File API. This raied a lot of questions, as I've written about here, here and here.

Starting with API 23 (Android 6), things seem to change yet again...

The problem

For API 23, there are at least 2 things that are new and are storage-related :

  • "Adoptable Storage Devices" - The user can optionally make the SD-card as something that's like the primary external storage.
  • As part of the new permissions mechanism (requesting permissions at runtime), it seems that storage is also a permission the user needs to confirm. This is for both READ_EXTERNAL_STORAGE and WRITE_EXTERNAL_STORAGE

Since there is no Android 6 device out there that has SD-card, and because the emulator itself doesn't really have the ability to use an SD-card, it's still impossible to know what's going on.

The questions

  1. Will the SD-card get the access using the File-API instead of DocumentFile?

  2. If I want access to all external storage paths (including SD-card), does this mean I need to request this permissions twice: one for the primary external storage and one for the SD-card?

  3. Are files on the SD-card accessible in any way before the manual granting of the permission?

  4. Suppose the user has chosen to use "Adoptable Storage Devices", what does it mean for the various functions that retrieve the paths of the app's files? For example : getFilesDir, getExternalFilesDir,... ? Would the oder of getExternalFilesDirs change because of it?

  5. What happens to the files of the app when the user moves the app from/to the SD-card (using the "Adoptable Storage Devices") ? What about the app's files on the SD-card? Would they stay? Or would they move somewhere?

    For example, if the app has "file1.txt" on the SD-card, on path "/storage/extSdCard/Android/data/appPackageName", and it has a file "file2.txt" (or even the same name) on the primary external storage on path "/storage/emulated/0/Android/data/appPackageName". After switching, what would happen for those files? How would they merge into a single folder, if at all?

  6. When moving the app to the SD-card (using "Adoptable Storage Devices"), does it mean no internal storage will be used?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Let me answer Adoptable Storage Devices related questions:

  1. Suppose the user has chosen to use "Adoptable Storage Devices", what does it mean for the various functions that retrieve the paths of the app's files? For example : getFilesDir, getExternalFilesDir,... ? Would the oder of getExternalFilesDirs change because of it?

When user choose to use SD card as "Adoptable Storage Device" (Format as internal), it means now that SD card is available only as Internal Storage i.e. no SD card available to store downloaded files. There will be no order change in paths returned by the related methods. For example: getExternalFilesDir() will list only external storage path if user formatted his SD card as "Adoptable Storage Devices". SD card path will not be available.

  1. What happens to the files of the app when the user moves the app from/to the SD-card (using the "Adoptable Storage Devices") ? What about the app's files on the SD-card? Would they stay? Or would they move somewhere? For example, if the app has "file1.txt" on the SD-card, on path "/storage/extSdCard/Android/data/appPackageName", and it has a file "file2.txt" (or even the same name) on the primary external storage on path "/storage/emulated/0/Android/data/appPackageName". After switching, what would happen for those files? How would they merge into a single folder, if at all?

When ever user will choose his SD card as "Adoptable Storage Devices" then user need to format his SD card as internal storage using "Format as internal" option. Format means all the data/files stored on SD card will be erased. Similarly when user want to remove his SD card from "Adoptable Storage Devices" then user again have to format his SD card as portable storage using "Format as portable" option.

  1. When moving the app to the SD-card (using "Adoptable Storage Devices"), does it mean no internal storage will be used?

Yes, original internal storage will not be used. Only SD card storage will be used because after choosing SD card as "Adoptable Storage Devices". All the data/cache will be stored to SD card


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...