Example usage for android.os Environment MEDIA_MOUNTED

List of usage examples for android.os Environment MEDIA_MOUNTED

Introduction

In this page you can find the example usage for android.os Environment MEDIA_MOUNTED.

Prototype

String MEDIA_MOUNTED

To view the source code for android.os Environment MEDIA_MOUNTED.

Click Source Link

Document

Storage state if the media is present and mounted at its mount point with read/write access.

Usage

From source file:Main.java

public static boolean checkSDcard() {
    return Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState());
}

From source file:Main.java

public static String mergeFlockedFiles(String FilePath) {

    String result = null;/*  w  w w. jav a2  s  .c  o m*/
    try {
        result = java.net.URLDecoder.decode(FilePath, "UTF-8");
    } catch (UnsupportedEncodingException e2) {
        // TODO Auto-generated catch block
        e2.printStackTrace();
    }
    String fileName = result.substring(result.lastIndexOf('/') + 1);
    if (android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED)) {

        File flockedFilesFolder = new File(
                Environment.getExternalStorageDirectory() + File.separator + "FlockLoad");
        System.out.println("FlockedFileDir: " + flockedFilesFolder);
        long leninfile = 0, leng = 0;
        int count = 1, data = 0;
        int bytesRead = 0;
        try {
            File filename = new File(flockedFilesFolder.toString() + "/" + fileName);
            if (filename.exists())
                filename.delete();
            //BUFFER_SIZE = (int) filename.length();
            System.out.println("filename: " + filename);
            FileOutputStream fos = new FileOutputStream(filename, true);

            while (true) {
                File filepart = new File(filename + ".part" + count);
                System.out.println("part filename: " + filepart);
                if (filepart.exists()) {
                    FileInputStream fis = new FileInputStream(filepart);
                    byte fileBytes[] = new byte[(int) filepart.length()];
                    bytesRead = fis.read(fileBytes, 0, (int) filepart.length());
                    assert (bytesRead == fileBytes.length);
                    assert (bytesRead == (int) filepart.length());
                    fos.write(fileBytes);
                    fos.flush();
                    fileBytes = null;
                    fis.close();
                    fis = null;
                    count++;
                    filepart.delete();
                } else
                    break;
            }
            fos.close();
            fos = null;
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    return fileName;
}

From source file:Main.java

public static File createTmpFile(Context context) throws IOException {
    File dir = null;//from   ww  w. j  av  a2 s . c o m
    if (TextUtils.equals(Environment.getExternalStorageState(), Environment.MEDIA_MOUNTED)) {
        dir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM);
        if (!dir.exists()) {
            dir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM + "/Camera");
            if (!dir.exists()) {
                dir = getCacheDirectory(context, true);
            }
        }
    } else {
        dir = getCacheDirectory(context, true);
    }
    return File.createTempFile(JPEG_FILE_PREFIX, JPEG_FILE_SUFFIX, dir);
}

From source file:Main.java

public static boolean isSDCardAvailable() {
    return Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState());
}

From source file:Main.java

public static boolean isExternalMemoryAvailable() {
    return android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED);
}

From source file:Main.java

public static boolean hasExternalStorage() {
    boolean externalStorage = Environment.getExternalStorageState()
            .equals(android.os.Environment.MEDIA_MOUNTED);
    return externalStorage;
}

From source file:Main.java

public static File createFile(Context context) {
    File file;//www .j  av a2s.  co m
    if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
        String timeStamp = String.valueOf(new Date().getTime());
        file = new File(Environment.getExternalStorageDirectory() + File.separator + timeStamp + ".jpg");
    } else {
        File cacheDir = context.getCacheDir();
        String timeStamp = String.valueOf(new Date().getTime());
        file = new File(cacheDir, timeStamp + ".jpg");
    }
    return file;
}

From source file:Main.java

public static boolean checkState() {
    boolean mExternalStorageAvailable = false;
    String state = Environment.getExternalStorageState();
    if (Environment.MEDIA_MOUNTED.equals(state)) {
        mExternalStorageAvailable = true;
    }/*  ww w  .  j av  a  2  s.c  o  m*/
    return mExternalStorageAvailable;
}

From source file:Main.java

private static boolean externalStorageAvailable() {
    return Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState());
}

From source file:Main.java

static public boolean externalStorageMounted() {
    String state = Environment.getExternalStorageState();
    return Environment.MEDIA_MOUNTED.equals(state) || Environment.MEDIA_MOUNTED_READ_ONLY.equals(state);
}