Why is the external storage on the simulator in a deleted state?

I am creating a playback application with data storage on external storage, however the code does not work on my simulator,

String state = Environment.getExternalStorageState(); 

The returned state always removed , and below are my simulator configurations, from which I set the size of the SD card to 200M, so I think the SD card should be mounted on the simulator. enter image description here

Do you know why?

+3
source share
1 answer

I checked your initialization. Well, that works. A few things you can try:

  • Check the application on a real device with a working SD card. Does your code give you the correct state? This would mean that this is not code, but really an emulator.
  • Use the following code in onCreate after calling super.onCreate . This will give you a toast showing the activation path to the external storage.

     Toast.makeText( this, Environment.getExternalStorageState() + ", " + Environment.getExternalStorageDirectory(), Toast.LENGTH_LONG) .show(); 
  • Make sure that your computer has a place to write the sd-card file. Depending on the operating system, this file can be found in the <home>/.android/avd/<device name>.avd/sdcard.img

  • Update to the latest Android SDK
0
source

Source: https://habr.com/ru/post/978661/


All Articles