0

I have read this tutorial about downloading database to my sd card and I have a question what will happen while the mobile phone does not have SD card? Then I have to download data to internal memory.

So how to check if device has got sd card or not and then set appropriate location before downloading? or maybe it will be done automatically because it use:

outFile = new File(Environment.getExternalStorageDirectory() + "/" + fileName);

Please help me if you know,

Thank you

Derek K
  • 2,756
  • 1
  • 21
  • 37

3 Answers3

0

I think it can be useful Android Storage Options. For database you can check sd-card state with getExternalStorageState(), or use Android SQL helper-class.

nfirex
  • 1,523
  • 18
  • 24
0

Some of Android phones doesnt have an sdcard slot but the internal memory is treated and simulated as external sdcard. Check this before.

To check the sd-card state: getExternalStorageState()

If it has sdcard (or simulated sdcard)

outFile = new File(Environment.getExternalStorageDirectory() + "/" + fileName);

If its better if you create a folder in the sdcard:

String sdpath = Environment.getExternalStorageDirectory().getAbsolutePath();

        File dir = new File(sdpath + "/AppFolder");
        dir.mkdir();
        outFile = new File(dir.toString() + "/" + fileName);

IF the phone dosnt have a simulated sdcard:

outFile = new File(fileName);

The location is data/data/mypackage/

nabrugir
  • 1,839
  • 2
  • 22
  • 38
-1
public static boolean isSdPresent() {

return android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED);

}
Ajmal Salim
  • 4,142
  • 2
  • 33
  • 41