3

I don't have an Android device to test this (yeah, i know. Android developer without an Android device) but i was wondering if in case there is either NO sdcard in the device, or the sdcard is full, when i need to store some data during the execution of my app, will it return an IOException? Or will it just store it automatically in the phone's memory? OR what happens in this situation, and what are the best steps to pursue?

AndreiBogdan
  • 10,858
  • 13
  • 58
  • 106
  • 1
    It will thrown IOException with message No space left on the device – Blackbelt Jul 17 '12 at 09:15
  • And when it does that, i should try writing on the phone's memory right? And if that throws an exception as well, i should just tell the user he hasn't got enough memory? Is this the correct procedure? – AndreiBogdan Jul 17 '12 at 09:16
  • 2
    Best option IMO is always to inform the user and let him free same space. Avoid writing the phone memory – Blackbelt Jul 17 '12 at 09:25

2 Answers2

4

you could check if the sd card is mounted or not

Is there a way to tell if the sdcard is mounted vs not installed at all?

EDIT: you can check the availaible space in your phone (sdcard/internal)

How to Check available space on android device ? on SD card?

you might find this useful too.. An IOException IS thrown if you exceed the storage limit.

IOException is thrown when SDCard is full

Community
  • 1
  • 1
Vinay W
  • 9,912
  • 8
  • 41
  • 47
  • And if i can't use the sdcard for whatever reason, they i should try writing on the phone's memory? And if that doesn't work as well, then i should just display a message to the user? – AndreiBogdan Jul 17 '12 at 09:19
  • that works. as long as your app logic allows to do each of those without creating a problem – Vinay W Jul 17 '12 at 09:20
1

You can setup the emulator so it uses a SD card and then fill it up with for example "dd". This should give you an environment you can use to test your application in the case when there is no room left on your SD card.

wojciii
  • 4,253
  • 1
  • 30
  • 39