List of usage examples for android.os Environment MEDIA_MOUNTED
String MEDIA_MOUNTED
To view the source code for android.os Environment MEDIA_MOUNTED.
Click Source Link
From source file:Main.java
public static boolean isExternalStorageAvailable() { return Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()); }
From source file:Main.java
public static String GetSdcardSystemPath() { String rootpath = ""; if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) { rootpath = Environment.getExternalStorageDirectory().toString(); }/*from ww w .jav a 2s . c om*/ return rootpath; }
From source file:Main.java
/** Create a File for saving an image or video */ public static File getOutputMediaFile(int type) { if (!Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) return null; File mediaStorageDir = new File( Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), "MacauFood"); // This location works best if you want the created images to be shared // between applications and persist after your app has been uninstalled. // Create the storage directory if it does not exist if (!mediaStorageDir.exists()) { if (!mediaStorageDir.mkdirs()) { Log.d("MacauFood", "failed to create directory"); return null; }/* w ww. j a v a 2 s . c o m*/ } // Create a media file name String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()); File mediaFile; if (type == MEDIA_TYPE_IMAGE) { mediaFile = new File(mediaStorageDir.getPath() + File.separator + "IMG_" + timeStamp + ".jpg"); } else if (type == MEDIA_TYPE_VIDEO) { mediaFile = new File(mediaStorageDir.getPath() + File.separator + "VID_" + timeStamp + ".mp4"); } else { return null; } return mediaFile; }
From source file:Main.java
public static boolean isExternalStorageWritable() { // get the external storage condition String state = Environment.getExternalStorageState(); // if writable if (Environment.MEDIA_MOUNTED.equals(state)) { return true; }//from w w w .ja va 2 s .co m return false; }
From source file:Main.java
/** * Returns application cache directory. Cache directory will be created on SD card * <i>("/Android/data/[app_package_name]/cache")</i> if card is mounted. Else - Android defines cache directory on * device's file system.// ww w. ja v a 2s . c o m * * @param context Application context * @return Cache {@link File directory} */ public static File getCacheDirectory(Context context) { File appCacheDir = null; if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) { appCacheDir = getExternalCacheDir(context); } if (appCacheDir == null) { appCacheDir = context.getCacheDir(); } return appCacheDir; }
From source file:Main.java
public static File getAlbumDir() { if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) { File dir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES); File storageDir = new File(dir, "MyAlbum"); if (!storageDir.mkdirs()) { if (!storageDir.exists()) { return null; }/* w ww . ja va2 s. c om*/ } return storageDir; } else { return null; } }
From source file:Main.java
public static String unzip(String filename) throws IOException { BufferedOutputStream origin = null; String path = null;//from w w w . ja v a2s . c o m Integer BUFFER_SIZE = 20480; 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 compressedFile = flockedFilesFolder.toString() + "/" + filename; System.out.println("compressed File name:" + compressedFile); //String uncompressedFile = flockedFilesFolder.toString()+"/"+"flockUnZip"; File purgeFile = new File(compressedFile); try { ZipInputStream zin = new ZipInputStream(new FileInputStream(compressedFile)); BufferedInputStream bis = new BufferedInputStream(zin); try { ZipEntry ze = null; while ((ze = zin.getNextEntry()) != null) { byte data[] = new byte[BUFFER_SIZE]; path = flockedFilesFolder.toString() + "/" + ze.getName(); System.out.println("path is:" + path); if (ze.isDirectory()) { File unzipFile = new File(path); if (!unzipFile.isDirectory()) { unzipFile.mkdirs(); } } else { FileOutputStream fout = new FileOutputStream(path, false); origin = new BufferedOutputStream(fout, BUFFER_SIZE); try { /* for (int c = bis.read(data, 0, BUFFER_SIZE); c != -1; c = bis.read(data)) { origin.write(c); } */ int count; while ((count = bis.read(data, 0, BUFFER_SIZE)) != -1) { origin.write(data, 0, count); } zin.closeEntry(); } finally { origin.close(); fout.close(); } } } } finally { bis.close(); zin.close(); purgeFile.delete(); } } catch (Exception e) { e.printStackTrace(); } return path; } return null; }
From source file:Main.java
public static boolean externalMemoryAvailable() { return android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED); }
From source file:Main.java
private static File createMediaFile(Context context, String parentPath) { String state = Environment.getExternalStorageState(); File rootDir = state.equals(Environment.MEDIA_MOUNTED) ? Environment.getExternalStorageDirectory() : context.getCacheDir();//from www. j ava 2 s . c om File folderDir = new File(rootDir.getAbsolutePath() + parentPath); if (!folderDir.exists() && folderDir.mkdirs()) { } String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.CHINA).format(new Date()); String fileName = APP_NAME + "_" + timeStamp + ""; File tmpFile = new File(folderDir, fileName + POSTFIX); return tmpFile; }
From source file:Main.java
/** * Helper method to initiate cache directory. It will return the cache directory in File format, * or NULL if the directory path is invalid or not accessible. *//*from w w w . ja va 2 s . co m*/ public static File getCacheDirectory(final Context context, final String path) { File cacheDir = null; if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) { try { cacheDir = context.getExternalCacheDir(); } catch (NullPointerException e) { // Fallback to use internal storage if external storage isn't available. } } if (cacheDir == null) { cacheDir = context.getCacheDir(); } return (cacheDir != null && path != null) ? new File(cacheDir, path) : null; }