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 hasSDCard() { // SD????????
    String status = Environment.getExternalStorageState();
    return status.equals(Environment.MEDIA_MOUNTED);
}

From source file:Main.java

/**
 * Get disk cache directory//from w w  w. java 2  s  .c  om
 *
 * @param ctx
 * @param uniqueName Unique name for caching directory, use it separate different types of cached files. eg: bitmap,strings,css,files etc.
 * @return cache directory
 */
public static File getDiskCacheDir(Context ctx, String uniqueName) {

    String cachePath;
    if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())
            || !Environment.isExternalStorageRemovable()) {
        cachePath = ctx.getExternalCacheDir().getPath();
    } else {
        cachePath = ctx.getCacheDir().getPath();
    }

    return new File(cachePath, uniqueName);
}

From source file:Main.java

public static void init(Context context) {
    voice_wechat_paths = new ArrayList<>();
    voice_qq_paths = new ArrayList<>();

    if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
        File dir = Environment.getExternalStorageDirectory();
        File f = new File(dir + "/tencent/MicroMsg");

        if (f.exists() && f.canRead() && f.isDirectory()) {
            File[] files = f.listFiles();
            if (files == null || files.length == 0) {
                return;
            }/*from  w w w .  j  a  v  a2  s.  c  o  m*/

            for (File f0 : files) {
                if (f0.isDirectory() && f0.getName().length() > 24) {
                    voice_wechat_paths.add(f0.getAbsolutePath() + "/voice2");
                }
            }
        }

        File exportDir = new File(dir, "silkv3_mp3");
        if (!exportDir.exists()) {
            exportDir.mkdirs();
        }

        export_dir = exportDir.getAbsolutePath();
    }
}

From source file:Main.java

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

From source file:Main.java

/**
 * //from   w w  w  .  j av a2s. c  o m
 * @param subDirName
 * @return
 */
public static String[] constructFileList(String subDirName) {
    List<String> fileList = null;

    String state = Environment.getExternalStorageState();

    if (Environment.MEDIA_MOUNTED.equals(state)) {
        File subDir = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator
                + DIR_NAME + File.separator + subDirName);

        if (subDir.exists()) {
            File[] files = subDir.listFiles();

            for (int i = 0; i < files.length; i++) {
                if (fileList == null) {
                    fileList = new ArrayList<String>();
                }

                // remove the extension
                fileList.add(files[i].getName().split("\\.")[0]);
            }
        } else {
            Log.e(LOG_TAG, "Nothing to import");
        }
    }

    return fileList.toArray(new String[fileList.size()]);
}

From source file:Main.java

/**
 * Checks if there is enough Space on SDCard
 *
 * @param needSize Size to Check// w  ww. ja va2s .  co m
 * @return True if the Update will fit on SDCard, false if not enough space on SDCard Will also return false, if the
 *         SDCard is not mounted as read/write
 */
public static boolean enoughSpaceOnSdCard(long needSize) {
    String status = Environment.getExternalStorageState();
    if (!status.equals(Environment.MEDIA_MOUNTED)) {
        return false;
    }
    return (needSize < getRealSizeOnSdcard());
}

From source file:Main.java

/**
 * Get a writeable cache directory for saving cache files
 *
 * @param context/*from  ww w .j a  v a  2s .  c o  m*/
 * @return file directory or null
 */
public static File getApplicationCacheDirectory(Context context) {
    File directory = context.getFilesDir();

    String state = Environment.getExternalStorageState();
    if (Environment.MEDIA_MOUNTED.equals(state)) {
        File externalDirectory = context.getExternalFilesDir(null);
        if (externalDirectory != null) {
            directory = externalDirectory;
        }
    }

    File cacheDirectory = new File(directory, CACHE_DIRECTORY);
    if (!cacheDirectory.exists()) {
        cacheDirectory.mkdir();
    }

    return cacheDirectory;
}

From source file:Main.java

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

From source file:Main.java

public static String zip(String filename) throws IOException {
    BufferedInputStream origin = null;
    Integer BUFFER_SIZE = 20480;//from   w  ww . j av a2  s. c o m

    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);
        String uncompressedFile = flockedFilesFolder.toString() + "/" + filename;
        String compressedFile = flockedFilesFolder.toString() + "/" + "flockZip.zip";
        ZipOutputStream out = new ZipOutputStream(
                new BufferedOutputStream(new FileOutputStream(compressedFile)));
        out.setLevel(9);
        try {
            byte data[] = new byte[BUFFER_SIZE];
            FileInputStream fi = new FileInputStream(uncompressedFile);
            System.out.println("Filename: " + uncompressedFile);
            System.out.println("Zipfile: " + compressedFile);
            origin = new BufferedInputStream(fi, BUFFER_SIZE);
            try {
                ZipEntry entry = new ZipEntry(
                        uncompressedFile.substring(uncompressedFile.lastIndexOf("/") + 1));
                out.putNextEntry(entry);
                int count;
                while ((count = origin.read(data, 0, BUFFER_SIZE)) != -1) {
                    out.write(data, 0, count);
                }
            } finally {
                origin.close();
            }
        } finally {
            out.close();
        }
        return "flockZip.zip";
    }
    return null;
}

From source file:Main.java

public static boolean saveBitmapToLocal(String path, String fileName, Bitmap b) {
    if (b == null) {
        return false;
    }//from w  w  w .  j a v  a  2s. co  m

    boolean result = false;
    String storageState = Environment.getExternalStorageState();
    if (storageState.equals(Environment.MEDIA_MOUNTED)) {

        File dir = new File(path);
        if (!dir.exists()) {
            dir.mkdirs();
        }
        FileOutputStream fos = null;

        try {
            fos = new FileOutputStream(path + fileName);
            b.compress(CompressFormat.JPEG, 100, fos);
            fos.flush();
            result = true;
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                fos.close();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }

    }
    return result;
}