Navdroid Navdroid - 2 months ago 20
Android Question

Detecting Sdcard in android?

I am using the following code to access sdcard if mounted else using the internal memory:

if( android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED))
{
//File file = Environment.getExternalStorageDirectory();

videoPath=Environment.getExternalStorageDirectory()+"/cue_learn_data/video_files/"+VIDEO_FILENAME+".mp4";

}
else
{

videoPath="/cue_learn_data/video_files/"+VIDEO_FILENAME+".mp4";

}


But vidoePath is not found when I use first condition.Could anyone help?

Answer

try doing it in this way:

String tmp = "/cue_learn_data/video_files/"+VIDEO_FILENAME+".mp4";
File myFile= new File(Environment.getExternalStorageDirectory(), tmp);

if(myFile.exists()){
    //further processing as your file exists
}
else{
    //seems like your file doesnt exist
}