0

My app use the sd card for a SQLite DB. The device and sd card must be encrypted because some of the data on it (for the app) is proprietary. The app will fail if it is lunched immediately after a device restart because the sd card cannot be read (the notification bar says it is preparing the sd card). After the notification bar reports that the sd card is ready every thing is fine.

I have tried to test this with:

Boolean isSDPresent = android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED);

if(isSDPresent)
{
  // yes SD-card is present
}
else
{
 // Sorry
}

from this question:

Check whether the SD card is available or not programmatically

and I have tried this:

    boolean sdCardOK = false;

    String state = Environment.getExternalStorageState();
        if (Environment.MEDIA_MOUNTED.equals(state)) {
            sdCardOK = true;
        } else {

    //warn the user and kill the app

    }
}

based on:

http://developer.android.com/guide/topics/data/data-storage.html#filesExternal

I could maybe just put a test text file on the sd card and try to read that. If it fails then warn the user and kill the app. But I would like to do something a little better. It seams like I should be able to get this info from the android os...

The device used for development (and for deployment) is the Samsung Tab 4. The SD cards are PNY 32GB and Kingston 32GB.

Community
  • 1
  • 1
fallingdog
  • 192
  • 1
  • 2
  • 17
  • Does it make a difference for this question if the SD card contents are encrypted? – Maarten Bodewes Sep 07 '14 at 01:37
  • Just tried it with a tablet that I have not yet encrypted the SD card on. There is no issue, everything works as expected. I feel like this maybe a case google did not think about... – fallingdog Sep 09 '14 at 20:34

1 Answers1

1

1.put this filed to main class

private boolean sdpresent = false;

2.put this codes to oncrate method

        Timer timer = new Timer();
        TimerTask timerTask = new TimerTask() {
            @Override
            public void run() {
                sdpresent = android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED);
            }
        };
        timer.schedule(timerTask, 0, 1000);

after run,each 1 second,re check sd card present

if sdcard present: sdpresent = true;

mohammadjv
  • 38
  • 6