List of usage examples for android.os Environment getExternalStorageDirectory
public static File getExternalStorageDirectory()
From source file:Main.java
public static void copyBitmapToTempFile(Uri uri) { File picture = new File(Environment.getExternalStorageDirectory() + "/yourName", "temp"); FileOutputStream out = null;/*from ww w . java 2s . c o m*/ InputStream is = null; try { is = mActivity.getContentResolver().openInputStream(uri); out = new FileOutputStream(picture); byte[] buffer = new byte[1024]; while (is.read(buffer) != -1) { out.write(buffer); } is.close(); is = null; out.close(); out = null; } catch (FileNotFoundException e) { } catch (IOException e) { } finally { try { if (is != null) { is.close(); is = null; } if (out != null) { out.close(); out = null; } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
From source file:Main.java
/** * Takes care of creating a directory for our application on the device's storage and * then returns the full path to it//from w ww . j ava 2s . c o m * @return The full path to the directory where our sound files will be stored */ private static String getDirectoryPath() { // Replace the path here with your own File file = new File(Environment.getExternalStorageDirectory(), "/GenericAndroidSoundboard/Audio/"); // Create the directory if it doesn't exist if (!file.exists()) { file.mkdirs(); } // Get the path to the newly created directory return Environment.getExternalStorageDirectory().getAbsolutePath() + "/GenericAndroidSoundboard/Audio/"; }
From source file:Main.java
public static String showFileAvailable() { String result = ""; if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) { StatFs sf = new StatFs(Environment.getExternalStorageDirectory().getPath()); long blockSize = sf.getBlockSize(); long blockCount = sf.getBlockCount(); long availCount = sf.getAvailableBlocks(); return showFileSize(availCount * blockSize) + " / " + showFileSize(blockSize * blockCount); }/*from www. j av a2s .c o m*/ return result; }
From source file:Main.java
public static void installApkFromLocalPath(Activity activity, String apkname) { Intent intent = new Intent(Intent.ACTION_VIEW); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.setDataAndType(//ww w . j ava 2 s . c o m Uri.parse("file://" + Environment.getExternalStorageDirectory() + "/ewgvip/" + apkname), "application/vnd.android.package-archive"); activity.startActivity(intent); }
From source file:Main.java
public static String getAvailableStoragePath(Context context) { if (BASE_DIR == null) { try {// ww w . j av a2 s . c o m BASE_DIR = Environment.getExternalStorageDirectory().getAbsolutePath(); StorageManager sStorageManager = (StorageManager) context.getSystemService(Context.STORAGE_SERVICE); Class<?> smClazz = sStorageManager.getClass(); Method listMethod = smClazz.getDeclaredMethod("getVolumeList"); Object vlObject = listMethod.invoke(sStorageManager); if (vlObject.getClass().isArray()) { String state = null; String path = null; // Class svClazz = // Class.forName("android.os.storage.StorageVolume"); Object svObject = Array.get(vlObject, 1); if (svObject != null) { Method pathMethod = svObject.getClass().getMethod("getPath"); path = (String) pathMethod.invoke(svObject); Method stateMethod = smClazz.getMethod("getVolumeState", new Class[] { String.class }); state = (String) stateMethod.invoke(sStorageManager, path); } if (path != null && state != null && state.equals(Environment.MEDIA_MOUNTED)) { BASE_DIR = path; } else { BASE_DIR = Environment.getExternalStorageDirectory().getAbsolutePath(); } } } catch (Exception e) { BASE_DIR = Environment.getExternalStorageDirectory().getAbsolutePath(); } return BASE_DIR; } else { return BASE_DIR; } }
From source file:Main.java
/** * Get SDCard cache dir./* w w w . ja v a2 s.c o m*/ * * @param context * @return */ public static String getSdCacheDir(Context context) { if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) { java.io.File fExternalStorageDirectory = Environment.getExternalStorageDirectory(); java.io.File autonaviDir = new java.io.File(fExternalStorageDirectory, "move"); boolean result = false; if (!autonaviDir.exists()) { result = autonaviDir.mkdir(); } java.io.File minimapDir = new java.io.File(autonaviDir, "offlineMap"); if (!minimapDir.exists()) { result = minimapDir.mkdir(); } return minimapDir.toString() + File.separator; } else { return ""; } }
From source file:Main.java
public static File getMultimediaDirectory() { File multimediaDirectory = new File(Environment.getExternalStorageDirectory() + File.separator + "LiteracyApp" + File.separator + "multimedia"); if (!multimediaDirectory.exists()) { multimediaDirectory.mkdirs();//from w w w .j a v a 2 s . c o m } return multimediaDirectory; }
From source file:Main.java
public static void saveToFile(Bitmap... bitmaps) { int i = 0;//from w w w . j a v a2s. c o m for (Bitmap bitmap : bitmaps) { String path = Environment.getExternalStorageDirectory().getPath(); File file = new File(path + "/" + (i++) + ".jpg"); FileOutputStream fos = null; try { fos = new FileOutputStream(file); } catch (FileNotFoundException e) { e.printStackTrace(); } bitmap.compress(CompressFormat.JPEG, 100, fos); try { fos.flush(); fos.close(); } catch (IOException e) { e.printStackTrace(); } } }
From source file:Main.java
public static String writeBitmap(byte[] data) throws IOException { File file = new File(Environment.getExternalStorageDirectory() + "/bookclip/"); file.mkdir();/* ww w . j a v a 2 s . c om*/ String bitmapPath = file.getPath() + "/" + System.currentTimeMillis() + ".jpg"; FileOutputStream outStream = new FileOutputStream(bitmapPath); outStream.write(data); outStream.close(); return bitmapPath; }
From source file:Main.java
/** * @param imgName//from www.j av a 2 s. c o m * @return */ public static Bitmap getBitmapFromPath(String imgName) { String sExtendSdcardDir = ""; String sAppRoot = ""; String sdcardRoot = Environment.getExternalStorageDirectory() == null ? "" : Environment.getExternalStorageDirectory().getAbsolutePath(); Log.d("Tiny", "sdcardRoot --" + sdcardRoot); if (sdcardRoot != null) { sExtendSdcardDir = sdcardRoot; sAppRoot = sExtendSdcardDir.concat("/TINY"); } String sCache = sAppRoot.concat("/cache"); File file = new File(sCache); if (!file.exists()) { file.mkdirs(); } Log.d("Tiny", "file path --" + file.getAbsolutePath()); File image = new File(file.getAbsolutePath(), imgName); BitmapFactory.Options bmOptions = new BitmapFactory.Options(); Bitmap bitmap = BitmapFactory.decodeFile(image.getAbsolutePath(), bmOptions); return bitmap; }