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:link.kjr.file_manager.MainActivity.java
public void clickPictures(View view) { String path = (Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES)) .getAbsolutePath();//from ww w.j ava2 s . c o m setDirectoryView(path); Log.i(BuildConfig.APPLICATION_ID, " set to Pictures"); }
From source file:com.bloc.blocparty.TimelineFragment.java
/** Create a File for saving an image or video */ private File getOutputMediaFile(int type) { // To be safe, you should check that the SDCard is mounted if (Environment.getExternalStorageState() != null) { // this works for Android 2.2 and above File mediaStorageDir = new File( Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), "AndroidCameraTestsFolder"); // 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()) { return null; }/*www. j a v a2s. co m*/ } // Create a media file name String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()); File mediaFile; if (type == MEDIA_TYPE_IMAGE) { mFileName = "IMG_" + timeStamp + ".jpg"; mediaFile = new File(mediaStorageDir.getPath() + File.separator + mFileName); } else if (type == MEDIA_TYPE_VIDEO) { mFileName = "VID_" + timeStamp + ".mp4"; mediaFile = new File(mediaStorageDir.getPath() + File.separator + mFileName); } else { return null; } return mediaFile; } return null; }
From source file:com.example.android.scopeddirectoryaccess.ScopedDirectoryAccessFragment.java
private String getDirectoryName(String name) { switch (name) { case "ALARMS": return Environment.DIRECTORY_ALARMS; case "DCIM": return Environment.DIRECTORY_DCIM; case "DOCUMENTS": return Environment.DIRECTORY_DOCUMENTS; case "DOWNLOADS": return Environment.DIRECTORY_DOWNLOADS; case "MOVIES": return Environment.DIRECTORY_MOVIES; case "MUSIC": return Environment.DIRECTORY_MUSIC; case "NOTIFICATIONS": return Environment.DIRECTORY_NOTIFICATIONS; case "PICTURES": return Environment.DIRECTORY_PICTURES; case "PODCASTS": return Environment.DIRECTORY_PODCASTS; case "RINGTONES": return Environment.DIRECTORY_RINGTONES; default://w ww .ja va 2 s . co m throw new IllegalArgumentException("Invalid directory representation: " + name); } }
From source file:ar.com.lapotoca.resiliencia.gallery.ui.ImageDetailActivity.java
private Uri getLocalBitmapUri(ImageView imageView) { // Extract Bitmap from ImageView drawable Drawable drawable = imageView.getDrawable(); Bitmap bmp;/*from w w w . j ava 2 s . com*/ if (drawable instanceof BitmapDrawable) { bmp = ((BitmapDrawable) imageView.getDrawable()).getBitmap(); } else { return null; } if (bmp == null) { return null; } // Store image to default external storage directory Uri bmpUri = null; try { // Use methods on Context to access package-specific directories on external storage. // This way, you don't need to request external read/write permission. // See https://youtu.be/5xVh-7ywKpE?t=25m25s File file = new File(getExternalFilesDir(Environment.DIRECTORY_PICTURES), "share_image_" + System.currentTimeMillis() + ".png"); FileOutputStream out = new FileOutputStream(file); bmp.compress(Bitmap.CompressFormat.PNG, 90, out); out.close(); bmpUri = Uri.fromFile(file); } catch (IOException e) { e.printStackTrace(); } return bmpUri; }
From source file:com.business.rushour.businessapp.RiderMainActivity.java
private static File getOutputMediaFile(int type) { // External sdcard location File mediaStorageDir = new File( Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), IMAGE_DIRECTORY_NAME);/*w w w . j a v a2 s . com*/ // Create the storage directory if it does not exist if (!mediaStorageDir.exists()) { if (!mediaStorageDir.mkdirs()) { Log.d(IMAGE_DIRECTORY_NAME, "Oops! Failed create " + IMAGE_DIRECTORY_NAME + " directory"); return null; } } // Create a media file name String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.getDefault()).format(new Date()); File mediaFile; if (type == MEDIA_TYPE_IMAGE) { mediaFile = new File(mediaStorageDir.getPath() + File.separator + "IMG_" + timeStamp + ".jpg"); } else { return null; } return mediaFile; }
From source file:io.jawg.osmcontributor.ui.activities.PhotoActivity.java
private File createImageFile() throws IOException { // Create an image file name String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.FRANCE).format(new Date()); String imageFileName = "JPEG_" + timeStamp + "_"; File storageDir = getExternalFilesDir(Environment.DIRECTORY_PICTURES); return File.createTempFile(imageFileName, ".jpg", storageDir); }
From source file:it.rignanese.leo.slimfacebook.MainActivity.java
@TargetApi(Build.VERSION_CODES.HONEYCOMB) 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 */ );/*from w w w .j ava 2 s.co m*/ return imageFile; }
From source file:com.luke.lukef.lukeapp.NewUserActivity.java
/** * Creates an image file from the photo that was taken *//* ww w . ja v a 2s . co m*/ private void createImageFile() { // Create an image file name String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.getDefault()).format(new Date()); String imageFileName = "JPEG_" + timeStamp + "_"; File storageDir = getExternalFilesDir(Environment.DIRECTORY_PICTURES); File image = null; try { image = File.createTempFile(imageFileName, /* prefix */ ".jpg", /* suffix */ storageDir /* directory */ ); } catch (IOException e) { Log.e(TAG, "createImageFile: ", e); } // Save a file: path for use with ACTION_VIEW intents if (image != null) { this.photoPath = image.getAbsolutePath(); this.photoFile = image; } }
From source file:com.dazone.crewchat.libGallery.activity.BucketHomeFragmentActivity.java
/** * Create a File for saving an image or video *//*from w ww . ja v a 2 s.co m*/ private static File getOutputMediaFile(int type) { File mediaStorageDir = new File( Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), MediaChooserConstants.folderName); if (!mediaStorageDir.exists()) { if (!mediaStorageDir.mkdirs()) { return null; } } // 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; }
From source file:es.upv.riromu.arbre.main.MainActivity.java
@Override protected void onRestoreInstanceState(@NonNull Bundle savedInstanceState) { super.onRestoreInstanceState(savedInstanceState); if (savedInstanceState.containsKey("cropping")) { state[CROP_IMAGE] = savedInstanceState.getBoolean("cropping"); }//from w ww .java 2 s . com if (savedInstanceState.containsKey("treated")) { state[TREAT_IMAGE] = savedInstanceState.getBoolean("treated"); } if (savedInstanceState.containsKey("image_uri")) { image_uri = Uri.parse(savedInstanceState.getString("image_uri")); } if (savedInstanceState.getBoolean("image")) { String fileName = "temp_image.jpg"; String fileURL = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).getPath() + "/" + fileName; File file = new File(fileURL); try { InputStream imageStream = getContentResolver().openInputStream(Uri.fromFile(file)); image = Util.decodeScaledBitmapFromFile(file.getPath(), MAX_SIZE, MAX_SIZE); // image = BitmapFactory.decodeStream(imageStream); } catch (FileNotFoundException e) { Log.e(TAG, e.getMessage()); } } if (state[CROP_IMAGE]) { String fileName = "temp_cropped.jpg"; String fileURL = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).getPath() + "/" + fileName; File file = new File(fileURL); try { InputStream imageStream = getContentResolver().openInputStream(Uri.fromFile(file)); croppedimage = BitmapFactory.decodeStream(imageStream); imageStream.close(); } catch (FileNotFoundException e) { Log.e(TAG, e.getMessage()); } catch (IOException e) { Log.e(TAG, e.getMessage()); } } if (state[TREAT_IMAGE]) { String fileName = "temp_treated.jpg"; String fileURL = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).getPath() + "/" + fileName; File file = new File(fileURL); try { InputStream imageStream = getContentResolver().openInputStream(Uri.fromFile(file)); ImageView imv = (ImageView) findViewById(R.id.image_intro); imv.setImageBitmap(BitmapFactory.decodeStream(imageStream)); imageStream.close(); } catch (FileNotFoundException e) { Log.e(TAG, e.getMessage()); } catch (IOException e) { Log.e(TAG, e.getMessage()); } } ImageView imv = (ImageView) findViewById(R.id.image_intro); colours = savedInstanceState.getIntArray("colours"); if ((!state[TREAT_IMAGE]) && state[CROP_IMAGE]) imv.setImageBitmap(croppedimage); else { imv.setImageBitmap(image); } TextView imc = (TextView) findViewById(R.id.textView); imc.setBackgroundColor(Color.rgb(colours[COLOUR_R], colours[COLOUR_G], colours[COLOUR_B])); }