简体   繁体   中英

Android : Sd Card Validation

How do i validate if the Sdcard is available or not? My application is save some voice to sdcard. If there's no memory card means, my app will force close. I don't know what can i do in that time. Could anyone please, how can i validate this before i've save the data to memory card.

Update

I've found for above this and got good answer from SO users also. Now, i want to check the Memory card size is full or not? How can i done this? Anyone Guide Me.

Thanks in Advance.

Sdcard is mounted or not .....

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

    // SD Card is mounted

} else {

    // SD Card is not mounted

}

I've find a Way from Here .

It provides Simple way to Check that -

String state = Environment.getExternalStorageState();
if(Environment.MEDIA_MOUNTED.equals(state) || Environment.MEDIA_MOUNTED_READ_ONLY.equals(state))
{
   //Whatever we want
}else
{
   //Whatever we want
}

Thanks for all of you Replying My Question.

您可以在保存之前检查外部存储状态

There are a couple of different ways to do this, but the best one is probably to use getExternalFilesDir . This will return null if the sdcard is not available. An added bonus is that it will be removed, when the user removes your application.

If you do not wish to use this feature, you can simply see if your directory exists, or if you can create it. Eg. if(!dir.exists() && !dir.mkdirs()) then external storage is not available.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM