Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

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

import android.os.Environment;
import android.text.TextUtils;
import android.util.Log;

public class Main {
    /** Log TAG */
    private static final String TAG = "StorageUtils";

    public static boolean isExternalStorageWriteable() {
        boolean writealbe = false;
        long start = System.currentTimeMillis();
        if (TextUtils.equals(Environment.MEDIA_MOUNTED, Environment.getExternalStorageState())) {
            File esd = Environment.getExternalStorageDirectory();
            if (esd.exists() && esd.canWrite()) {
                File file = new File(esd, ".696E5309-E4A7-27C0-A787-0B2CEBF1F1AB");
                if (file.exists()) {
                    writealbe = true;
                } else {
                    try {
                        writealbe = file.createNewFile();
                    } catch (IOException e) {
                        Log.w(TAG, "isExternalStorageWriteable() can't create test file.");
                    }
                }
            }
        }
        long end = System.currentTimeMillis();
        Log.i(TAG, "Utility.isExternalStorageWriteable(" + writealbe + ") cost " + (end - start) + "ms.");
        return writealbe;
    }
}