androidandroid-studioandroid-emulatorandroid-device-monitor

Can't push files to SD card in Android emulator in API 25


I have been testing my app on Android emulator with an API version of 23 which works very well, but in other versions it doesn't work as well. I need to push some files into the downloads directory, and so far it hasn't worked on an emulator running API 25. The logcat of Android Device Monitor is constantly spammed with all sorts of messages.

Errors in Android device monitor

I was able to get the error

[timestamp] Failed to push the item(s).

[timestamp] null

before restarting Android Studio, but since I restarted I can't find a message like this. So my problem seems to have something in common with this


Solution

  • How are you finding the download directory? If you're using a hard path (e.g. /.../Downloads/) you shouldn't, instead use the storage APIs. This is because multi-users are introduced which breaks using a hard path.

    More specifically, you probably want to use getExternalStoragePublicDirectory(Enviornment.DIRECTORY_DOWNLOADS)

    For more info on storage, see the documentation