List of usage examples for android.os Environment DIRECTORY_DCIM
String DIRECTORY_DCIM
To view the source code for android.os Environment DIRECTORY_DCIM.
Click Source Link
From source file:net.ddns.mlsoftlaberge.trycorder.TryviscamFragment.java
/** * Create a File for saving an image or video */// w w w.j ava 2 s . c o m private static File getOutputMediaFile(int type) { // To be safe, you should check that the SDCard is mounted // using Environment.getExternalStorageState() before doing this. File mediaStorageDir = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM), "Camera"); // 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("Trycorder", "failed to create directory"); return null; } } // 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:com.annanovas.bestprice.DashBoardEditActivity.java
public File createImageFile() throws IOException { // Create an image file name String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()); String imageFileName = "JPEG_" + timeStamp + "_"; File storageDir = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM), "Best Price"); if (!storageDir.exists()) { storageDir.mkdirs();//from ww w. java 2s . c om } File image = File.createTempFile(imageFileName, /* prefix */ ".jpg", /* suffix */ storageDir /* directory */ ); // Save a file: path for use with ACTION_VIEW intents imageUri = "file:" + image.getAbsolutePath(); return image; }
From source file:com.almalence.opencam.SavingService.java
public static File getSaveDir(boolean forceSaveToInternalMemory) { File dcimDir, saveDir = null, memcardDir; boolean usePhoneMem = true; String abcDir = "Camera"; if (sortByData) { Calendar rightNow = Calendar.getInstance(); abcDir = String.format("%tF", rightNow); }//from w ww.j ava 2 s.c o m if (Integer.parseInt(saveToPreference) == 1) { dcimDir = Environment.getExternalStorageDirectory(); for (int i = 0; i < SAVEDIR_DIR_PATH_NAMES.length; i++) { if (MEMCARD_DIR_PATH[i].isEmpty()) { memcardDir = new File(dcimDir, MEMCARD_DIR_PATH_NAMES[i]); if (memcardDir.exists()) { saveDir = new File(dcimDir, SAVEDIR_DIR_PATH_NAMES[i] + abcDir); usePhoneMem = false; break; } } else { memcardDir = new File(MEMCARD_DIR_PATH[i], MEMCARD_DIR_PATH_NAMES[i]); if (memcardDir.exists()) { saveDir = new File(MEMCARD_DIR_PATH[i], SAVEDIR_DIR_PATH_NAMES[i] + abcDir); usePhoneMem = false; break; } } } } else if ((Integer.parseInt(saveToPreference) == 2)) { if (sortByData) { saveDir = new File(saveToPath, abcDir); } else { saveDir = new File(saveToPath); } usePhoneMem = false; } if (usePhoneMem || forceSaveToInternalMemory) // phone memory (internal // sd card) { dcimDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM); saveDir = new File(dcimDir, abcDir); } if (!saveDir.exists()) saveDir.mkdirs(); // if creation failed - try to switch to phone mem if (!saveDir.exists()) { dcimDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM); saveDir = new File(dcimDir, abcDir); if (!saveDir.exists()) saveDir.mkdirs(); } return saveDir; }
From source file:com.gelakinetic.mtgfam.fragments.CardViewFragment.java
/** * Returns the File used to save this card's image * * @param shouldDelete true if the file should be deleted before returned, false otherwise * @return A File, either with the image already or blank * @throws Exception If something goes wrong *///from w w w . j a va 2s. c o m private File getSavedImageFile(boolean shouldDelete) throws Exception { String strPath; try { strPath = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM).getCanonicalPath() + "/MTGFamiliar"; } catch (IOException ex) { throw new Exception(getString(R.string.card_view_no_pictures_folder)); } File fPath = new File(strPath); if (!fPath.exists()) { if (!fPath.mkdir()) { throw new Exception(getString(R.string.card_view_unable_to_create_dir)); } if (!fPath.isDirectory()) { throw new Exception(getString(R.string.card_view_unable_to_create_dir)); } } fPath = new File(strPath, mCardName + "_" + mSetCode + ".jpg"); if (shouldDelete) { if (fPath.exists()) { if (!fPath.delete()) { throw new Exception(getString(R.string.card_view_unable_to_create_file)); } } } return fPath; }
From source file:com.almalence.opencam.SavingService.java
@TargetApi(19) public static DocumentFile getSaveDirNew(boolean forceSaveToInternalMemory) { DocumentFile saveDir = null;/*from w ww .ja v a 2 s.co m*/ boolean usePhoneMem = true; String abcDir = "Camera"; if (sortByData) { Calendar rightNow = Calendar.getInstance(); abcDir = String.format("%tF", rightNow); } int saveToValue = Integer.parseInt(saveToPreference); if (saveToValue == 1 || saveToValue == 2) { boolean canWrite = false; String uri = saveToPath; try { saveDir = DocumentFile.fromTreeUri(ApplicationScreen.instance, Uri.parse(uri)); } catch (Exception e) { saveDir = null; } List<UriPermission> perms = ApplicationScreen.instance.getContentResolver() .getPersistedUriPermissions(); for (UriPermission p : perms) { if (p.getUri().toString().equals(uri.toString()) && p.isWritePermission()) { canWrite = true; break; } } if (saveDir != null && canWrite && saveDir.exists()) { if (sortByData) { DocumentFile dateFolder = saveDir.findFile(abcDir); if (dateFolder == null) { dateFolder = saveDir.createDirectory(abcDir); } saveDir = dateFolder; } usePhoneMem = false; } } if (usePhoneMem || forceSaveToInternalMemory) // phone memory (internal // sd card) { saveDir = DocumentFile .fromFile(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM)); DocumentFile abcFolder = saveDir.findFile(abcDir); if (abcFolder == null || !abcFolder.exists()) { abcFolder = saveDir.createDirectory(abcDir); } saveDir = abcFolder; } return saveDir; }