Example usage for android.os Environment DIRECTORY_DCIM

List of usage examples for android.os Environment DIRECTORY_DCIM

Introduction

In this page you can find the example usage for android.os Environment DIRECTORY_DCIM.

Prototype

String DIRECTORY_DCIM

To view the source code for android.os Environment DIRECTORY_DCIM.

Click Source Link

Document

The traditional location for pictures and videos when mounting the device as a camera.

Usage

From source file:fpt.isc.nshreport.utilities.FileUtils.java

public static File resizeImage(File file, int sizeMax) {
    try {//  w  w  w .j  ava 2s  . c o  m

        // BitmapFactory options to downsize the image
        BitmapFactory.Options o = new BitmapFactory.Options();
        o.inJustDecodeBounds = true;
        o.inSampleSize = 6;
        // factor of downsizing the image

        FileInputStream inputStream = new FileInputStream(file);
        //Bitmap selectedBitmap = null;
        BitmapFactory.decodeStream(inputStream, null, o);
        inputStream.close();

        // The new size we want to scale to
        final int REQUIRED_SIZE = sizeMax;

        // Find the correct scale value. It should be the power of 2.
        int scale = 1;
        while ((o.outWidth) / scale >= REQUIRED_SIZE && (o.outHeight) / scale >= REQUIRED_SIZE) {
            scale *= 2;
        }

        BitmapFactory.Options o2 = new BitmapFactory.Options();
        o2.inSampleSize = scale;
        inputStream = new FileInputStream(file);

        Bitmap selectedBitmap = BitmapFactory.decodeStream(inputStream, null, o2);
        inputStream.close();

        // here i override the original image file
        /*String imageFileName = "JPEG_NSH_";
        File storageDir = new File(Environment.getExternalStoragePublicDirectory(
            Environment.DIRECTORY_DCIM), "Camera");
        File image = File.createTempFile(
            imageFileName,
            ".jpg",
            storageDir
        );*/

        String imageFileName = "JPEG_NSH.jpg";
        File storageDir = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM),
                "Camera");

        File image = new File(storageDir, imageFileName);

        // Save a file: path for use with ACTION_VIEW intents
        FileOutputStream outputStream = new FileOutputStream(image);

        selectedBitmap.compress(Bitmap.CompressFormat.JPEG, 100, outputStream);

        return image;
    } catch (Exception e) {
        return null;
    }
}

From source file:chinanurse.cn.nurse.Fragment_Nurse_job.IdentityFragment_ACTIVITY.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode != RESULT_CANCELED) {
        switch (requestCode) {
        case PHOTO_REQUEST_CAMERA:// 
            // ????
            String state = Environment.getExternalStorageState();
            if (state.equals(Environment.MEDIA_MOUNTED)) {
                File path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM);
                File tempFile = new File(path, "newpic.jpg");
                startPhotoZoom(Uri.fromFile(tempFile));
            } else {
                Toast.makeText(activity, "??", Toast.LENGTH_SHORT)
                        .show();//  ww  w .  j a v a2s.  co  m
            }
            break;
        case PHOTO_REQUEST_ALBUM:// 
            startPhotoZoom(data.getData());
            break;

        case PHOTO_REQUEST_CUT: // ??
            if (data != null) {
                getImageToView(data);
            }
            break;
        }
    }
    super.onActivityResult(requestCode, resultCode, data);
}

From source file:org.openmrs.mobile.activities.addeditpatient.AddEditPatientFragment.java

@NeedsPermission({ Manifest.permission.CAMERA, Manifest.permission.WRITE_EXTERNAL_STORAGE })
public void capturePhoto() {
    Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    if (takePictureIntent.resolveActivity(getContext().getPackageManager()) != null) {
        File dir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM);
        output = new File(dir, getUniqueImageFileName());
        takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(output));
        startActivityForResult(takePictureIntent, IMAGE_REQUEST);
    }/*from  ww  w.ja va2  s .c  om*/
}

From source file:net.gsantner.opoc.util.ShareUtil.java

/**
 * Request a picture from camera-like apps
 * Result ({@link String}) will be available from {@link Activity#onActivityResult(int, int, Intent)}.
 * It has set resultCode to {@link Activity#RESULT_OK} with same requestCode, if successfully
 * The requested image savepath has to be stored at caller side (not contained in intent),
 * it can be retrieved using {@link #extractResultFromActivityResult(int, int, Intent)},
 * returns null if an error happened.//  w w  w  . j  av  a  2  s .co m
 *
 * @param target Path to file to write to, if folder the filename gets app_name + millis + random filename. If null DCIM folder is used.
 */
public String requestCameraPicture(File target) {
    if (!(_context instanceof Activity)) {
        throw new RuntimeException("Error: ShareUtil.requestCameraPicture needs an Activity Context.");
    }
    String cameraPictureFilepath = null;
    Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    if (takePictureIntent.resolveActivity(_context.getPackageManager()) != null) {
        File photoFile;
        try {
            // Create an image file name
            if (target != null && !target.isDirectory()) {
                photoFile = target;
            } else {
                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH-mm-ss", Locale.getDefault());
                File storageDir = target != null ? target
                        : new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM),
                                "Camera");
                String imageFileName = ((new ContextUtils(_context).rstr("app_name"))
                        .replaceAll("[^a-zA-Z0-9\\.\\-]", "_") + "_").replace("__", "_")
                        + sdf.format(new Date());
                photoFile = new File(storageDir, imageFileName + ".jpg");
                if (!photoFile.getParentFile().exists() && !photoFile.getParentFile().mkdirs()) {
                    photoFile = File.createTempFile(imageFileName + "_", ".jpg", storageDir);
                }
            }

            //noinspection StatementWithEmptyBody
            if (!photoFile.getParentFile().exists() && photoFile.getParentFile().mkdirs())
                ;

            // Save a file: path for use with ACTION_VIEW intents
            cameraPictureFilepath = photoFile.getAbsolutePath();
        } catch (IOException ex) {
            return null;
        }

        // Continue only if the File was successfully created
        if (photoFile != null) {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
                Uri uri = FileProvider.getUriForFile(_context, getFileProviderAuthority(), photoFile);
                takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
            } else {
                takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile));
            }
            ((Activity) _context).startActivityForResult(takePictureIntent, REQUEST_CAMERA_PICTURE);
        }
    }
    _lastCameraPictureFilepath = cameraPictureFilepath;
    return cameraPictureFilepath;
}

From source file:kr.ac.kpu.wheeling.blackbox.Camera2VideoFragment.java

public File getVideoStorageDir(String albumName) {
    //File file = new File(Environment.getExternalStorageDirectory(), albumName);
    File file = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM), albumName);

    if (canWritable() && !file.isDirectory()) {
        if (!file.mkdirs()) {
            Log.e("STORAGE", "Directory not created");
        }/*from  w  w w.  j a va  2 s  .c  o m*/
    }

    return file;
}

From source file:us.theparamountgroup.android.inventory.EditorActivity.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 = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM),
            "Camera");
    File image = File.createTempFile(imageFileName, /* prefix */
            ".jpg", /* suffix */
            storageDir /* directory */
    );/*www.ja v a  2 s  .co m*/

    // Save a file: path for use with ACTION_VIEW intents
    mCurrentPhotoPath = "file:" + image.getAbsolutePath();
    Log.i(LOG_TAG, "in createImageFile mCurrentPhotoPath: " + mCurrentPhotoPath);
    return image;
}

From source file:org.awesomeapp.messenger.MainActivity.java

void startPhotoTaker() {

    // create Intent to take a picture and return control to the calling application
    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    File photo = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM),
            "cs_" + new Date().getTime() + ".jpg");
    mLastPhoto = Uri.fromFile(photo);/*w w w.j ava2s . c  om*/
    intent.putExtra(MediaStore.EXTRA_OUTPUT, mLastPhoto);

    // start the image capture Intent
    startActivityForResult(intent, ConversationDetailActivity.REQUEST_TAKE_PICTURE);
}

From source file:com.gelakinetic.selfr.CameraActivity.java

/**
 * Create a File for saving an image/* w w w .j  av a  2s .c  o  m*/
 */
@Nullable
private File getOutputImageFile() {
    /* Make sure the external storage is mounted first */
    if (!Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
        return null;
    }

    /* Make a Selfr folder in the DCIM directory */
    File mediaStorageDir = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM),
            getString(R.string.app_name));

    /* Create the storage directory if it does not exist */
    if (!mediaStorageDir.exists()) {
        if (!mediaStorageDir.mkdirs()) {
            /* Can't make the folder */
            return null;
        }
    }

    /* Create a media file name */
    String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.getDefault()).format(new Date());
    return new File(mediaStorageDir.getPath() + File.separator + "IMG_" + timeStamp + ".jpg");
}

From source file:info.guardianproject.otr.app.im.app.NewChatActivity.java

void startPhotoTaker() {

    // create Intent to take a picture and return control to the calling application
    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    File photo = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM),
            "cs_" + new Date().getTime() + ".jpg");
    mLastPhoto = Uri.fromFile(photo);/* w  w w.  j av  a 2  s  .  c  o  m*/
    intent.putExtra(MediaStore.EXTRA_OUTPUT, mLastPhoto);

    // start the image capture Intent
    startActivityForResult(intent, REQUEST_TAKE_PICTURE);
}

From source file:info.guardianproject.otr.app.im.app.NewChatActivity.java

void startPhotoTakerSecure() {

    // create Intent to take a picture and return control to the calling application
    Intent intent = new Intent(this, SecureCameraActivity.class);
    String time = "" + new Date().getTime();
    String filename = "/" + Environment.DIRECTORY_DCIM + "/" + "cs_" + time + ".jpg";
    String thumbnail = "/" + Environment.DIRECTORY_DCIM + "/" + "cs_" + time + "_thumb.jpg";
    intent.putExtra(SecureCameraActivity.FILENAME, filename);
    intent.putExtra(SecureCameraActivity.THUMBNAIL, thumbnail);

    // start the secure image capture Intent
    startActivityForResult(intent, REQUEST_TAKE_PICTURE_SECURE);
}