List of usage examples for android.os Environment getExternalStorageState
public static String getExternalStorageState()
From source file:Main.java
public static Uri createUri(String foldername) { String storageState = Environment.getExternalStorageState(); if (storageState.equals(Environment.MEDIA_MOUNTED)) { final File root = new File( Environment.getExternalStorageDirectory() + File.separator + foldername + File.separator); root.mkdirs();//from w ww .j av a 2s .co m final String fname = getUniqueImageFilename(foldername); final File sdImageMainDirectory = new File(root, fname); return Uri.fromFile(sdImageMainDirectory); } return null; }
From source file:Main.java
public static File getWritableFileDir(Context context) { if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) { File file = context.getExternalFilesDir(null); if (file == null) { file = context.getFilesDir(); }//from ww w . j a v a 2s. co m return file; } else { return context.getFilesDir(); } }
From source file:Main.java
public static String getSdCacheDir(Context context) { if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) { if (true) { Context appContext = context.getApplicationContext(); File amap = appContext.getExternalFilesDir("offlineMap"); return amap.getAbsolutePath() + "/"; } else {//from w w w .ja va2 s .c o m File fExternalStorageDirectory = Environment.getExternalStorageDirectory(); File autonaviDir = new File(fExternalStorageDirectory, "amapsdk"); boolean result = false; if (!autonaviDir.exists()) { result = autonaviDir.mkdir(); } File minimapDir = new File(autonaviDir, "offlineMap"); if (!minimapDir.exists()) { result = minimapDir.mkdir(); } return minimapDir.toString() + "/"; } } else { return ""; } }
From source file:Main.java
/** * Simple helper to ensure that we can write to Android filesystem. * @return// w w w . j a v a 2s. co m */ public static boolean isExternalStorageWritable() { try { String state = Environment.getExternalStorageState(); if (Environment.MEDIA_MOUNTED.equals(state)) { return true; } return false; } catch (Exception e) { return false; } }
From source file:Main.java
/** * Checks if the external Storage is available * @return//from w w w . j a va 2 s. c o m */ public static boolean isExternalStorageAvailable() { String state = Environment.getExternalStorageState(); if (state.equals(Environment.MEDIA_MOUNTED)) { return true; } else { return false; } }
From source file:Main.java
public static String getAvaibleSDCardPath() { String str = Environment.getExternalStorageDirectory().getAbsolutePath(); if (!Environment.getExternalStorageState().equals("mounted")) { str = INTERNAL_CARD;//from w ww. j av a 2 s. co m } return str; }
From source file:Main.java
public static boolean checkSdCard() { // if (android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED)) { if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) { isSdCard = true;// ww w. java 2s .c o m } else { isSdCard = false; } return isSdCard; }
From source file:Main.java
public static String getSavePath() { String savePath = null;/* ww w . java 2 s . c o m*/ if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) { savePath = Environment.getExternalStorageDirectory().getAbsolutePath(); } else { File[] files = new File("/mnt/").listFiles(); if (files.length > 0) { String filePath = null; for (int p = 0; p < files.length; p++) { if (files[p].isDirectory()) { if (files[p].getPath().indexOf("sdcard") >= 0) { StatFs st = new StatFs(files[p].getPath()); int blocksize = st.getBlockSize(); int blockcount = st.getBlockCount(); if ((blocksize * blockcount) > 0) { filePath = files[p].getPath(); } } } } if (filePath != null) { savePath = filePath; } else { savePath = null; } } } return savePath; }
From source file:Main.java
public static String getDownloadDir() { String status = Environment.getExternalStorageState(); if (status == null || !status.equals(Environment.MEDIA_MOUNTED)) { return null; }//from ww w . j a v a2 s. c om String path = null; // get the sdcard directory File sdFile = Environment.getExternalStorageDirectory(); if (null != sdFile) { path = sdFile.toString(); } else { path = "/sdcard/"; } path += "/download"; File destDir = new File(path); if (!destDir.exists()) { try { if (!destDir.mkdirs()) { Log.e("getDownloadDir", "create folder " + path + " failed"); return null; } } catch (SecurityException e) { Log.e("getDownloadDir", "create folder " + path + " failed: " + e.toString()); return null; } } return path; }
From source file:Main.java
public static boolean checkSDCard() { if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) { return true; } else {/*from ww w .ja v a 2s .c om*/ return false; } }