Method for Android 8.0 to read internal and external storage and external SDcard

  • 2021-10-11 19:37:18
  • OfStack

Recently, I encountered the question of reading SDcard. I haven't seen this part for a long time, so I roughly looked at it 1 time and recorded it 1 time by the way. Tested on Android 8.0.

There are three main types of storage space that can be read by the general Android App:

app's own private directory, which is/data/data/" app Directory ".

No separate permissions are required to read and write this directory. Each app can only read and write its own directory, but not the directories of other app. Android manages permissions through Seandroid.

/sdcard.

This is actually internal storage of Android mobile phone. That is to say, when you buy a mobile phone, you say that the mobile phone is the storage space of 64GB, that is to say, this place. You need to apply for permission to read and write in this place. READ_EXTERNAL_STORAGE is read, WRITE_EXTERNAL_STORAGE is write, and if you have write permission, you will automatically have read permission. This permission is right on the entire/sdcard, not the molecular directory, that is to say, 1 you can apply for permission on the entire/sdcard all files and directories have access. The management of this permission will be displayed in the corresponding app permission in settings.

External sdcard

This corresponds to the microSD card you put in the sdcard slot of your mobile phone. Sometimes called removable storage. In Android, it is impossible to obtain the right to read and write by applying for permission. This 1 point is different from the 2 mentioned above. Therefore, if you need to obtain write permission, you need the user to specify a specific directory for separate authorization. Here's a simple example. If the path of the external sdcard is/mnt/extsdcard, and then there are two directories on it, a and b, then you can ask the user to authorize you to write/mnt/extsdcard/a, but you need to ask the user to authorize you to write/mnt/extsdcard/b separately, that is, to authorize twice. Specific implementation method, not much said, google and github to give an example, which wiki page has a more detailed description.

In particular, since there is no corresponding android permission, if you are authorized, the corresponding directory path will not display app permission in settings. Instead, it displays app storage, where the user can authorize revoke to app (again, specify the directory). I don't feel good about this, because it is also a matter of permission in essence, which should be put in app permission.


Related articles: