MaiaVictor
MaiaVictor

Reputation: 53037

Android: can't debug file writting code because my SD card gets mounted

I am programming a temporary file-downloader inside my app. That file-downloader is crashing. The problem is: I can't debug it, because when the phone is connected to the computer, the SD card gets locked and it can't write files. That is, it crashes because of that, and that's the error I see - hiding the actual error that is making it crash when it is not mounted.

Upvotes: 1

Views: 1103

Answers (1)

Marcin Orlowski
Marcin Orlowski

Reputation: 75636

You should check if SD card is mounted prior using it:

if (android.os.Environment.getExternalStorageState().equals(
                        android.os.Environment.MEDIA_MOUNTED)) {

      // ok, you can use SD card...
}

as, as comments above state, on some devices SD card access from host computer can block device's access to it. Also just in case, ensure your manifest request SD card permissions too.

Upvotes: 2

Related Questions