عثمان غني
عثمان غني

Reputation: 2708

Unable to write to storage in android

I have tried each and every solution on SO about writing to external storage. working on it from 2 days but unable to write in Android Kitkat 4.2.2. I am clueless whats happening. My manifest files have Read & Write permissions and code for writing file is :

// make a new file directory inside the "sdcard" folder
    File mediaStorageDir = new File(Environment.getExternalStoragePublicDirectory(
            Environment.DIRECTORY_PICTURES), "imgcaptureapp");

    // if the directory does not exist
    if (!mediaStorageDir.exists()) {
        // if you cannot make this directory return
        if (!mediaStorageDir.mkdirs()) {
            return null;
        }
    }

    // take the current timeStamp
    String timeStamp = new SimpleDateFormat("dd-MM-yyyy_HH:mm:ss").format(new Date());
    File mediaFile;
    // and make a media file:
    mediaFile = new File(mediaStorageDir.getPath() + File.separator + "IMG_" + timeStamp + ".jpg");

    return mediaFile;

My mediaFile.canwrite(); returning false.

Upvotes: 0

Views: 318

Answers (1)

CommonsWare
CommonsWare

Reputation: 1007584

Colons are reserved characters in many filesystems, including Android's. On the whole, the simpler the filename that you use, with respect to punctuation-style characters, the better off you will be.

In this case, use a date-time format (e.g., YYYYMMDD-HHMMSS) that happens to not use colons.

Upvotes: 1

Related Questions