List of usage examples for android.os Environment getExternalStoragePublicDirectory
public static File getExternalStoragePublicDirectory(String type)
From source file:Main.java
public static String getImagePathInExternalStoragePublicDirectory(String filename) { File path = Environment.getExternalStoragePublicDirectory("uDrove"); File file = new File(path, filename + ".jpg"); path.mkdirs();//from w ww . jav a2s. c o m if (file.exists()) { return file.getPath(); } return ""; }
From source file:Main.java
public static File createImageFile(String imageFileName) throws IOException { File storageDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES); File image = File.createTempFile(imageFileName, /* prefix */ ".jpg", /* suffix */ storageDir /* directory */ );/* w ww . j a va 2 s .co m*/ return image; }
From source file:Main.java
@TargetApi(Build.VERSION_CODES.FROYO) public static File getDCIMFile() { return Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM); }
From source file:Main.java
public static File getDestinationInExternalPublicDir(String dirType, String fileName) { File file = Environment.getExternalStoragePublicDirectory(dirType); if (file.exists()) { if (!file.isDirectory()) { throw new IllegalStateException(file.getAbsolutePath() + " already exists and is not a directory"); }//from ww w.j ava2 s. c o m } else { if (!file.mkdirs()) { throw new IllegalStateException("Unable to create directory: " + file.getAbsolutePath()); } } //mDestinationUri = Uri.withAppendedPath(Uri.fromFile(file), subPath); /*File destFolder = new File(file.getAbsolutePath() + File.separator + DOWNLOAD_FOLDER); if (destFolder.exists()) { if (!destFolder.isDirectory()) { throw new IllegalStateException(file.getAbsolutePath() + " already exists and is not a directory"); } } else { if (!destFolder.mkdirs()) { throw new IllegalStateException("Unable to create directory: "+ destFolder.getAbsolutePath()); } } File destFile = new File(destFolder.getAbsolutePath() + File.separator + fileName);*/ return new File(file.getAbsolutePath() + File.separator + fileName); }
From source file:Main.java
public static String getSystemImagePath() { if (Build.VERSION.SDK_INT > 7) { String picturePath = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES) .getAbsolutePath();//from w ww . ja va2 s . c o m return picturePath + "/nim/"; } else { String picturePath = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM) .getAbsolutePath(); return picturePath + "/nim/"; } }
From source file:Main.java
public static String getSavePath(Context context) { boolean hasSDCard = Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED); if (hasSDCard) { return Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).toString(); }/*from ww w. j a v a2 s.co m*/ return context.getFilesDir().toString(); }
From source file:Main.java
public static File getMediaCopyFolder(Context context) { File mediaCopyFolder = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM), MEDIA_PUBLIC_FOLDER_NAME);// w ww. jav a 2s . com if (mediaCopyFolder.exists()) { // Log.d(TAG, "Media folder exist: " + mediaCopyFolder); } else { mediaCopyFolder.mkdirs(); // Log.d(TAG, "Media folder created: " + mediaCopyFolder); } return mediaCopyFolder; }
From source file:Main.java
public static File getAlbumStorageDir(String theenvironment, String albumName) { // Get the directory for the user's public pictures directory. File file = new File(Environment.getExternalStoragePublicDirectory(theenvironment), albumName); if (!file.mkdirs()) { //Log.e(TAG, "Directory not created"); }//from w w w .ja v a 2 s.c o m return file; }
From source file:Main.java
public static String getPhotoSavePath() { String dcimDir = null;//w w w . jav a 2 s .c om File extDcimDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM); if (extDcimDir == null || !extDcimDir.exists()) { File extDir = Environment.getExternalStorageDirectory(); if (extDir == null) { return null; } dcimDir = extDir.getAbsolutePath() + "/DCIM"; try { new File(dcimDir).mkdirs(); } catch (Exception e) { } } else { dcimDir = extDcimDir.getAbsolutePath(); } return dcimDir + PHOTO_FOLDER; }
From source file:Main.java
public static boolean writeToExternalStoragePublic(String filename, String fileContent) { boolean saved = false; String path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS) + "/"; if (isExternalStorageAvailable() && !isExternalStorageReadOnly()) { try {//from w w w .j a va 2s . c o m boolean exists = (new File(path)).exists(); if (!exists) { new File(path).mkdirs(); } //Remote legacy file File file = new File(path + filename); file.delete(); // Open output stream FileOutputStream fOut = new FileOutputStream(path + filename, true); fOut.write(fileContent.getBytes()); // Close output stream fOut.flush(); fOut.close(); saved = true; } catch (IOException e) { e.printStackTrace(); } } return saved; }