Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the expected behaviour of Adoptable Storage on Android M and how it should be handled by apps?

I am experimenting with the “Adoptable storage” introduced in Android Marshmallow and I need some guidance on the expected behaviour and how the apps should handle the “Adoptable storage”.

  • Format “micro SD” card as Adoptable storage by using “Format as Internal”
  • Once Format is done, there are 2 options given to the user as follows:
    1. Move Now
    2. Move Later

a. Move Now: When this option is chosen by the user, the path returned by the getExternalFilesDirs is “/storage/emulated/0/Android/data/PACKAGE_NAME/files” and it actually points to the file system of micro SD card.

b. Move Later: When this option is chosen by the user, the path returned by the getExternalFilesDirs is “/storage/emulated/0/Android/data/PACKAGE_NAME/files” and it actually points to the file system of Internal embedded memory.

In both the cases, the apps can see only one storage and the other storage is completely not accessible by the Apps to store data such as Photos, Videos, etc. Is there any way to access the storage paths of both the Internal and micro SD card when the micro SD card is formatted as “Adoptable storage” ?

Apart from this documentation ,I could not find a detailed documentation on how the apps should handle this adopted storage. Is there any API that app needs to use?

Example:

Let say, if the user phone has Internal memory of 32 GB and micro SD card of 32 GB. If the card is formatted as “Portable storage”, both 32GB(Internal) and 32GB(micro SD card) are available to user to store data.

But If the user format the card as “Internal Memory”, the user can save data(photos/video/music,etc) only to any of this 32 GB storage location, but not to the both location. The system is providing an option of “Migrating data” between the storage locations(Internal to micro SD card and viceversa), but the apps can use only 32 GB of storage(The user effectively loses his 32 GB of storage to store Media files and can be only used to install the apps ?).

Is this the expected behaviour ?

Note: Test devices used - Moto X Play & HTC 10 - Both running Android 6.0.1 enter image description here

like image 216
Sivaraj Velusamy Avatar asked Nov 22 '25 05:11

Sivaraj Velusamy


1 Answers

getExternalFilesDir() always points to the external storage, which may or may not be available. Use getFilesDir() to dynamically get the path to wherever the App is currently stored.

Don't store the result of this since Adoptable Storage may move your app around at any time. From the docs:

The returned path may change over time if the calling app is moved to an adopted storage device, so only relative paths should be persisted.

like image 87
Aaron Brager Avatar answered Nov 24 '25 19:11

Aaron Brager