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:ar.com.lapotoca.resiliencia.gallery.ui.ImageDetailActivity.java
@Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.image_menu, menu); MenuItem shareItem = menu.findItem(R.id.menu_share); shareItem.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { @Override//www .j av a2s. c o m public boolean onMenuItemClick(MenuItem item) { try { ImageHolder img = Images.image[mPager.getCurrentItem()]; if (img == null) { return false; } AnalyticsHelper.getInstance().sendImageShareEvent(img.getUrl()); Uri bmpUri; if (img.isLocal()) { bmpUri = Uri.parse("content://" + AssetProvider.CONTENT_URI + "/" + img.getUrl()); } else { ImageView iv = (ImageView) findViewById(R.id.picImageView); bmpUri = getLocalBitmapUri(iv); } if (bmpUri != null) { Intent shareIntent = new Intent(); shareIntent.setAction(Intent.ACTION_SEND); shareIntent.putExtra(Intent.EXTRA_STREAM, bmpUri); shareIntent.setType("image/*"); startActivity(Intent.createChooser(shareIntent, getString(R.string.share_item))); AnalyticsHelper.getInstance().sendImageShareCompleted(); return true; } else { AnalyticsHelper.getInstance().sendImageShareCanceled(); return false; } } catch (Exception e) { AnalyticsHelper.getInstance().sendImageShareFailed(e.getMessage()); return false; } } }); MenuItem downloadItem = menu.findItem(R.id.download_asset); downloadItem.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { Context context = ImageDetailActivity.this; String appDirectoryName = context.getString(R.string.app_name); File imageRoot = new File( Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), appDirectoryName); ImageHolder img = Images.image[mPager.getCurrentItem()]; if (img == null) { return false; } AssetManager assetManager = context.getAssets(); try { InputStream is = assetManager.open(img.getUrl()); String fileName = img.getUrl().split("/")[1]; imageRoot.mkdirs(); File image = new File(imageRoot, fileName); byte[] buffer = new byte[BUFFER_LENGHT]; FileOutputStream fos = new FileOutputStream(image); int read = 0; while ((read = is.read(buffer, 0, 1024)) >= 0) { fos.write(buffer, 0, read); } fos.flush(); fos.close(); is.close(); String[] paths = { image.getAbsolutePath() }; MediaScannerConnection.scanFile(context, paths, null, null); NotificationHelper.showNotification(context, context.getString(R.string.download_image_succesfull)); AnalyticsHelper.getInstance().sendDownloadImage(fileName); } catch (Exception e) { NotificationHelper.showNotification(context, context.getString(R.string.download_no_permissions)); AnalyticsHelper.getInstance().sendImageDownloadFailed(e.getMessage()); } return true; } }); return true; }
From source file:com.microsoft.assetmanagement.DisplayCarActivity.java
/** * Creates the image file./*from ww w . j a v a2 s .c om*/ * * @return the file * @throws IOException Signals that an I/O exception has occurred. */ @SuppressLint("SimpleDateFormat") private File createImageFile() throws IOException { // Create an image file name String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()); String imageFileName = "JPEG_" + timeStamp + "_"; File storageDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES); File image = File.createTempFile(imageFileName, /* prefix */ ".jpg", /* suffix */ storageDir /* directory */ ); // Save a file: path for use with ACTION_VIEW intents mCurrentPhotoPath = image.getAbsolutePath(); return image; }
From source file:com.example.linhdq.test.documents.creation.NewDocumentActivity.java
protected void startCamera() { try {/*from w w w . j a va 2s .co m*/ cameraPicUri = null; dateCameraIntentStarted = new Date(); Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); // Create an image file name String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.US).format(new Date()); String imageFileName = "JPEG_" + timeStamp + "_"; File storageDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES); File image; try { if (!storageDir.exists()) { storageDir.mkdirs(); } image = new File(storageDir, imageFileName + ".jpg"); if (image.exists()) { image.createNewFile(); } cameraPicUri = Uri.fromFile(image); intent.putExtra(MediaStore.EXTRA_OUTPUT, cameraPicUri); startActivityForResult(intent, REQUEST_CODE_MAKE_PHOTO); } catch (IOException e) { showFileError(PixLoadStatus.IO_ERROR); } } catch (ActivityNotFoundException e) { showFileError(PixLoadStatus.CAMERA_APP_NOT_FOUND); } }
From source file:com.glanznig.beepme.data.DataExporter.java
public String exportToZipFile(Bundle opts) { boolean exportPhotos = opts.getBoolean("photoExport", true); boolean exportRaw = opts.getBoolean("rawExport", false); int densityFactor = opts.getInt("densityFactor", 1); //external storage is ready and writable - can be used if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) { File exportDir = ctx.getExternalFilesDir(EXPORT_DIR); if (!exportDir.exists()) { exportDir.mkdirs();// w w w . ja va 2 s . c o m } BeeperApp app = (BeeperApp) ctx.getApplicationContext(); String exportFilename = EXPORT_PREFIX; if (app.getPreferences().isTestMode()) { exportFilename += "testmode_"; } exportFilename += new SimpleDateFormat("yyyyMMddHHmmss").format(Calendar.getInstance().getTime()) + ".zip"; File exportFile = new File(exportDir, exportFilename); ArrayList<File> fileList = new ArrayList<File>(); String archive = null; String dbName; File picDir = ctx.getExternalFilesDir(Environment.DIRECTORY_PICTURES); if (app.getPreferences().isTestMode()) { dbName = StorageHandler.getTestModeDatabaseName(); picDir = new File(picDir, PhotoUtils.TEST_MODE_DIR); } else { dbName = StorageHandler.getProductionDatabaseName(); picDir = new File(picDir, PhotoUtils.NORMAL_MODE_DIR); } if (exportRaw) { fileList.add(ctx.getDatabasePath(dbName)); } // create temp dir for CSV and photos File tempDir = new File(exportDir, TEMP_DIR_NAME); tempDir.mkdirs(); File dataCSV = writeDataCSV(tempDir); File historyCSV = writeHistoryCSV(tempDir); if (dataCSV != null && dataCSV.exists()) { fileList.add(dataCSV); } if (historyCSV != null && historyCSV.exists()) { fileList.add(historyCSV); } if (exportPhotos) { if (picDir.exists()) { FilenameFilter filter = new FilenameFilter() { public boolean accept(File directory, String fileName) { return fileName.endsWith(".jpg"); } }; File[] photos = picDir.listFiles(filter); if (densityFactor > 1) { // downscale photos for (int i = 0; i < photos.length; i++) { String srcUri = photos[i].getAbsolutePath(); File destPhoto = new File(srcUri); destPhoto = new File(tempDir, destPhoto.getName()); String destUri = destPhoto.getAbsolutePath(); Bundle dim = PhotoUtils.getPhotoDimensions(srcUri); int width = dim.getInt("width"); int height = dim.getInt("height"); if (width > 0 && height > 0) { Bitmap scaledPhoto = PhotoUtils.scalePhoto(srcUri, destUri, (int) Math.round(width / Math.sqrt((double) densityFactor)), (int) Math.round(height / Math.sqrt((double) densityFactor))); if (scaledPhoto != null) { scaledPhoto.recycle(); fileList.add(destPhoto); } } } archive = zipFiles(exportFile, fileList); } else { for (int i = 0; i < photos.length; i++) { fileList.add(photos[i]); } archive = zipFiles(exportFile, fileList); } } } else { archive = zipFiles(exportFile, fileList); } // remove temp dir and contents File[] tempFiles; tempFiles = tempDir.listFiles(); for (int i = 0; i < tempFiles.length; i++) { tempFiles[i].delete(); } tempDir.delete(); return archive; } return null; }
From source file:jp.co.cyberagent.android.gpuimage.sample.activity.ActivityCamera.java
License:asdf
private static File getOutputMediaFile(final 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_PICTURES), "MyCameraApp"); // 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("MyCameraApp", "failed to create directory"); return null; }/* w w w .ja v a 2 s . c o m*/ } // 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.tomi.ginatask.MainActivity.java
/** Create a File for saving an image or video */ 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_PICTURES), "MyCameraApp"); //debug/*from w ww . ja v a 2s .c om*/ Log.i("Directory name: ", (Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES)).getPath()); // 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("MyCameraApp", "failed to create directory"); return null; } } // Create a media file name String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()); File mediaFile; if (type == MediaStore.Files.FileColumns.MEDIA_TYPE_IMAGE) { mediaFile = new File(mediaStorageDir.getPath() + File.separator + "IMG_" + timeStamp + ".jpg"); } else { return null; } return mediaFile; }
From source file:ch.dbrgn.android.simplerepost.activities.RepostActivity.java
/** * Save the specified bitmap to the external storage. The * fileIdentifier parameter should be unique among all instagram * posts. If the file can be written, a File object pointing * to it will be returned./* w w w.j a va 2s . c om*/ */ private File saveToExternalStorage(String fileIdentifier, Bitmap bitmap) { // Check whether external storage is writeable final String externalStorageState = Environment.getExternalStorageState(); boolean isWritable = externalStorageState.equals(Environment.MEDIA_MOUNTED); if (!isWritable) { ToastHelper.showShortToast(this, "External storage is not writeable."); return null; } // Create directory final File pubDirectory = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES); final File directory = new File(pubDirectory, Config.PICTURES_DIRECTORY_NAME); if (!directory.exists()) { if (!directory.mkdirs()) { ToastHelper.showShortToast(this, "Could not create storage directory."); return null; } } // Write file final File file = new File(directory, fileIdentifier + ".png"); if (file.exists()) { Log.w(LOG_TAG, "File " + file.toString() + " already exists"); // This can only happen if the file has been reposted before. // In that case, overwrite. if (!file.delete()) { Log.e(LOG_TAG, "File " + file.toString() + " could not be deleted."); ToastHelper.showGenericErrorToast(this); } else { Log.i(LOG_TAG, "Deleted file " + file); } } try { FileOutputStream os = new FileOutputStream(file); bitmap.compress(Bitmap.CompressFormat.PNG, 90, os); os.flush(); os.close(); } catch (IOException e) { e.printStackTrace(); ToastHelper.showGenericErrorToast(this); } return file; }
From source file:java_lang_programming.com.android_media_demo.ImageSelectionCropDemo.java
/** * ???/*from w w w . j av a 2s.c o m*/ * * @return */ private File getExternalStorageTempStoreFilePath() { File path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES); File file = new File(path, "selected_temp_image.jpg"); return file; }
From source file:com.renard.ocr.documents.creation.NewDocumentActivity.java
protected void startCamera() { mAnalytics.startCamera();//from ww w .j a va 2 s . com try { cameraPicUri = null; dateCameraIntentStarted = new Date(); Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); // Create an image file name String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.US).format(new Date()); String imageFileName = "JPEG_" + timeStamp + "_"; File storageDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES); File image; try { if (!storageDir.exists()) { storageDir.mkdirs(); } image = new File(storageDir, imageFileName + ".jpg"); if (image.exists()) { image.createNewFile(); } cameraPicUri = Uri.fromFile(image); intent.putExtra(MediaStore.EXTRA_OUTPUT, cameraPicUri); startActivityForResult(intent, REQUEST_CODE_MAKE_PHOTO); } catch (IOException e) { showFileError(PixLoadStatus.IO_ERROR); } } catch (ActivityNotFoundException e) { showFileError(PixLoadStatus.CAMERA_APP_NOT_FOUND); } }
From source file:com.purchasingpower.inappbrowser.WebViewActivity.java
private File createImageFile() throws IOException { // Create an image file name String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()); String imageFileName = "JPEG_" + timeStamp + "_"; File storageDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES); File imageFile = File.createTempFile(imageFileName, /* prefix */ ".jpg", /* suffix */ storageDir /* directory */ );/*www . jav a 2 s.com*/ return imageFile; }