check External Storage Directory Writable - Android Hardware

Android examples for Hardware:Storage

Description

check External Storage Directory Writable

Demo Code


//package com.java2s;
import java.io.File;
import java.io.IOException;

import android.os.Environment;

public class Main {
    static private boolean checkFsWritable() {
        String directoryName = Environment.getExternalStorageDirectory()
                .toString() + "/dcim";

        File directory = new File(directoryName);

        if (!directory.isDirectory()) {
            if (!directory.mkdirs()) {
                return false;
            }//  w  ww  . ja  va2 s  . c  o  m
        }

        File f = new File(directoryName, ".probe");
        try {
            // Remove stale file if any
            if (f.exists()) {
                f.delete();
            }
            if (!f.createNewFile())
                return false;
            f.delete();
            return true;
        } catch (IOException ex) {
            return false;
        }
    }
}

Related Tutorials