List of usage examples for android.os Environment DIRECTORY_PICTURES
String DIRECTORY_PICTURES
To view the source code for android.os Environment DIRECTORY_PICTURES.
Click Source Link
From source file:com.lcl6.cn.imagepickerl.AndroidImagePicker.java
/** * create a file to save photo/* w w w . j a va 2 s . c om*/ * @param ctx * @return */ private File createImageSaveFile(Context ctx) { if (Util.isStorageEnable()) { // File pic = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES); if (!pic.exists()) { pic.mkdirs(); } String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.CHINA).format(new Date()); String fileName = "IMG_" + timeStamp; File tmpFile = new File(pic, fileName + ".jpg"); mCurrentPhotoPath = tmpFile.getAbsolutePath(); Log.i(TAG, "=====camera path:" + mCurrentPhotoPath); return tmpFile; } else { //File cacheDir = ctx.getCacheDir(); File cacheDir = Environment.getDataDirectory(); String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.CHINA).format(new Date()); String fileName = "IMG_" + timeStamp; File tmpFile = new File(cacheDir, fileName + ".jpg"); mCurrentPhotoPath = tmpFile.getAbsolutePath(); Log.i(TAG, "=====camera path:" + mCurrentPhotoPath); return tmpFile; } }
From source file:com.gruporaido.tasker_library.util.Helper.java
/** * Create a new JPEG file on the public external storage. Uses current timestamp * to name the file.// w ww .j a v a2 s.c om * <b>Note: Files are accesible to other applications.</b> * * @return * @throws IOException */ public File createImageFile() throws IOException { String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()); String imageFileName = "JPEG_" + timeStamp + "_"; File storageDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES); return File.createTempFile(imageFileName, ".jpg", storageDir); }
From source file:com.rnd.snapsplit.view.OcrCaptureFragment.java
/** * Handles the requesting of the camera permission. This includes * showing a "Snackbar" message of why the permission is needed then * sending the request.//from ww w . ja v a 2 s . c o m */ private static File getOutputMediaFile() { File mediaStorageDir = new File( Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), "MyCameraApp"); if (!mediaStorageDir.exists()) { if (!mediaStorageDir.mkdirs()) { Log.d("MyCameraApp", "failed to create directory"); return null; } } // Create a media file name String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()); File mediaFile; mediaFile = new File(mediaStorageDir.getPath() + File.separator + "IMG_" + timeStamp + ".jpg"); return mediaFile; }
From source file:com.pixelpixel.pyp.MainActivity.java
public void saveFile() throws IOException { Drawable drw = img.getDrawable();/*www . j a va2 s .c o m*/ Bitmap savedPic = ((BitmapDrawable) drw).getBitmap(); OutputStream fOut = null; String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()); File mediaStorageDir = new File( Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), "Pimped pictures"); if (!mediaStorageDir.exists()) { if (!mediaStorageDir.mkdirs()) { Log.d("Pimp my picture", "failed to create directory"); return; } } try { File picFile = new File( mediaStorageDir.getPath() + File.separatorChar + "Pimped_" + timeStamp + ".jpg"); fOut = new FileOutputStream(picFile); picUri = Uri.fromFile(picFile); savedPic.compress(Bitmap.CompressFormat.JPEG, 95, fOut); fOut.flush(); fOut.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } }
From source file:com.hackensack.umc.activity.ProfileActivity.java
private File createImageFile() throws IOException { File image = null;/*from ww w . j a v a 2 s . c o m*/ File Folder = new File(Environment.getExternalStorageDirectory() + "/.mydir"); if (Folder.mkdir()) { // Create an image file name String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()); String imageFileName = "/.mydir" + "JPEG_" + timeStamp + "_"; File storageDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES); image = File.createTempFile(imageFileName, /* prefix */ ".jpg", /* suffix */ storageDir /* directory */ ); // Save a file: path for use with ACTION_VIEW intents mCurrentPhotoPath = "file:" + image.getAbsolutePath(); } return image; }
From source file:fr.tvbarthel.attempt.googlyzooapp.MainActivity.java
/** * Save screen capture into external storage * * @param screenBytes/* w w w.jav a 2 s . c o m*/ * @return path of the file */ private Uri writeScreenBytesToExternalStorage(byte[] screenBytes) { try { final SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy_MM_dd_HH_mm_HH_ss"); final String filePrefix = "screen_"; final String fileSuffix = ".jpg"; final String fileName = filePrefix + simpleDateFormat.format(new Date()) + fileSuffix; final File f = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES) + File.separator + "GooglyZoo", fileName); if (!f.getParentFile().isDirectory()) { f.getParentFile().mkdirs(); } f.createNewFile(); final FileOutputStream fo = new FileOutputStream(f); fo.write(screenBytes); fo.close(); return Uri.fromFile(f); } catch (IOException e) { Log.e(TAG, "error while saving screen", e); return null; } }
From source file:com.google.android.apps.forscience.whistlepunk.project.UpdateProjectFragment.java
private File createImageFile() throws IOException { String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()); String imageFileName = "JPEG_" + timeStamp + "_"; File storageDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES); // This file isn't really temporary and actually gets persisted in the users public // directory for the app. We store the path of this file and persist it in SQLite alongside // the project to retrieve it later. File imageFile = File.createTempFile(imageFileName, /* prefix */ ".jpg", /* suffix */ storageDir /* directory */ );//from w w w . j a v a2 s . com return imageFile; }
From source file:org.fs.galleon.presenters.ToolsFragmentPresenter.java
private Observable<File> createIfNotExists() { return Observable.just(toImageFileName()).flatMap(fileName -> { if (view.isAvailable()) { try { final Context context = view.getContext(); File storageDir = context.getExternalFilesDir(Environment.DIRECTORY_PICTURES); File temp = new File(storageDir, fileName + FILE_EXTENSION); boolean success = temp.createNewFile(); if (success) { log(Log.INFO, String.format(Locale.ENGLISH, "%s is temp created", temp.getName())); }// w w w .j a v a 2 s .c o m return Observable.just(temp); } catch (IOException ioError) { throw new AndroidException(ioError); } } return Observable.empty(); }); }
From source file:com.glanznig.beepme.BeeperApp.java
private void onAppUpdate(int oldVersion) { try {//from ww w . j a v a 2s. c o m PackageInfo packageInfo = this.getPackageManager().getPackageInfo(this.getPackageName(), 0); int newVersion = packageInfo.versionCode; //if (oldVersion > 0 && oldVersion != newVersion) { // if should be above line, change in future versions if (oldVersion < newVersion) { for (int mVers = oldVersion; mVers < newVersion; mVers++) { switch (mVers) { case 16: String dbName; String picDirName; if (getPreferences().isTestMode()) { dbName = StorageHandler.getTestModeDatabaseName(); picDirName = PhotoUtils.TEST_MODE_DIR; } else { dbName = StorageHandler.getProductionDatabaseName(); picDirName = PhotoUtils.NORMAL_MODE_DIR; } // rename the database if (!dbName.equals(StorageHandler.DB_OLD_NAME)) { File oldDb = getDatabasePath(StorageHandler.DB_OLD_NAME); File newDb = new File(oldDb.getParentFile(), dbName); oldDb.renameTo(newDb); } // move pictures if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) { File oldDir = this.getExternalFilesDir(Environment.DIRECTORY_PICTURES); File newDir = new File(oldDir.getAbsolutePath(), picDirName); if (!newDir.exists()) { newDir.mkdirs(); } File[] picFiles = oldDir.listFiles(new FilenameFilter() { public boolean accept(File dir, String name) { return name.toLowerCase().endsWith(".jpg"); } }); for (int i = 0; i < picFiles.length; i++) { picFiles[i].renameTo(new File(newDir, picFiles[i].getName())); } SampleTable st = new SampleTable(this); List<Sample> list = st.getSamples(); for (int i = 0; i < list.size(); i++) { Sample s = list.get(i); String uri = s.getPhotoUri(); if (uri != null) { File pic = new File(uri); s.setPhotoUri(pic.getParent() + File.separator + picDirName + File.separator + pic.getName()); st.editSample(s); } } } break; } } } // else we would have a new install or the data had been deleted getPreferences().setAppVersion(newVersion); } catch (PackageManager.NameNotFoundException nnfe) { } }
From source file:com.learnncode.mediachooser.activity.HomeScreenMediaChooser.java
private File getOutputMediaFile(int type) { File mediaStorageDir = new File( Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), MediaChooserConstants.folderName); if (!mediaStorageDir.exists()) { if (!mediaStorageDir.mkdirs()) { return null; }// www . j av a 2 s. co m } // Create a media file name String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()); File mediaFile; if (type == MediaChooserConstants.MEDIA_TYPE_IMAGE) { mediaFile = new File(mediaStorageDir.getPath() + File.separator + "IMG_" + timeStamp + ".jpg"); } else if (type == MediaChooserConstants.MEDIA_TYPE_VIDEO) { mediaFile = new File(mediaStorageDir.getPath() + File.separator + "VID_" + timeStamp + ".mp4"); } else { return null; } return mediaFile; }