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:Main.java

public static String getSystemImagePath() {
    if (Build.VERSION.SDK_INT > 7) {
        String picturePath = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES)
                .getAbsolutePath();/*  w w w  .ja v  a2  s. co  m*/
        return picturePath + "/nim/";
    } else {
        String picturePath = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM)
                .getAbsolutePath();
        return picturePath + "/nim/";
    }
}

From source file:Main.java

/**
 * Get the corresponding file of the dcimDirectory /sdcard/DCIM/name. Will
 * create the dcimDirectory if is doesn't exist.
 * /*from  w  w w.  j  a  v a  2 s.  co  m*/
 * @param dirName
 *            the dcimDirectory dirName.
 * @return the dcimDirectory's corresponding file.
 */
public static File getDcimDirectory(String dirName) {
    if (dirName == null) {
        return null;
    }

    File dcimDirectory = null;
    String dcimPath = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM).getPath();
    dcimDirectory = new File(dcimPath, dirName);
    if (!dcimDirectory.exists()) {
        dcimDirectory.mkdirs();
    }

    return dcimDirectory;
}

From source file:Main.java

/**
 * Retrieves FreeFlight media directory.
 * May return null.//  w  ww . j av  a  2 s.c  o m
 * @param context
 * @return Media directory to store the media files or null if sd card is not mounted.
 */
public static File getMediaFolder(Context context) {
    File dcimFolder = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM);

    if (dcimFolder == null) {
        Log.w(TAG, "Looks like sd card is not available.");
        return null;
    }

    File mediaFolder = new File(dcimFolder, MEDIA_PUBLIC_FOLDER_NAME);

    if (!mediaFolder.exists()) {
        mediaFolder.mkdirs();
        Log.d(TAG, "Root media folder created " + mediaFolder);
    }

    return mediaFolder;
}

From source file:Main.java

public static File createTmpFile(Context context) throws IOException {
    File dir = null;/*from   www .  j  a v  a 2  s  .c om*/
    if (TextUtils.equals(Environment.getExternalStorageState(), Environment.MEDIA_MOUNTED)) {
        dir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM);
        if (!dir.exists()) {
            dir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM + "/Camera");
            if (!dir.exists()) {
                dir = getCacheDirectory(context, true);
            }
        }
    } else {
        dir = getCacheDirectory(context, true);
    }
    return File.createTempFile(JPEG_FILE_PREFIX, JPEG_FILE_SUFFIX, dir);
}

From source file:Main.java

/** 
 * Create a file Uri for saving a recorded selfie
 *//*from w  ww .j  av  a 2 s .c o m*/
@SuppressLint("SimpleDateFormat")
public static Uri getRecordedGhostMySelfieUri(Context context) {

    // Check to see if external SDCard is mounted or not.
    if (isExternalStorageWritable()) {
        // Create a path where we will place our recorded selfie in
        // the user's public DCIM directory. Note that you should
        // be careful about what you place here, since the user
        // often manages these files.
        final File ghostmyselfieStorageDir = Environment
                .getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM);

        // Create the storage directory if it does not exist
        if (!ghostmyselfieStorageDir.exists()) {
            if (!ghostmyselfieStorageDir.mkdirs()) {
                return null;
            }
        }

        // Create a TimeStamp for the selfie file.
        final String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());

        // Create a selfie file name from the TimeStamp.
        final File ghostmyselfieFile = new File(
                ghostmyselfieStorageDir.getPath() + File.separator + "IMG_" + timeStamp + ".jpg");

        // Always notify the MediaScanners after storing
        // the GhostMySelfie, so that it is immediately available to
        // the user.
        notifyMediaScanners(context, ghostmyselfieFile);

        //Return Uri from GhostMySelfie file.
        return Uri.fromFile(ghostmyselfieFile);

    } else
        //Return null if no SDCard is mounted.
        return null;
}

From source file:Main.java

public static String getPhotoSavePath(String dir) {
    String dcimDir = null;// w w  w.j  a  va 2s  . c  o m

    File extDcimDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM);
    if (extDcimDir == null || !extDcimDir.exists()) {
        File extDir = Environment.getExternalStorageDirectory();
        if (extDir == null) {
            return null;
        }
        dcimDir = extDir.getAbsolutePath() + "/DCIM";
        try {
            new File(dcimDir).mkdirs();
        } catch (Exception e) {
        }
    } else {
        dcimDir = extDcimDir.getAbsolutePath();
    }
    if (dir == null) {
        return dcimDir + PHOTO_FOLDER;
    } else {
        return dcimDir + "/" + dir;
    }
}

From source file:Main.java

/** Create a File for saving an image */
public static File getOutputMediaFile(String name) {
    // 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)
            + "/Android/data/ca.sfu.mobileodr/Files");

    // 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;
        }//ww w .  j  a va  2s  . c  o m
    }
    // Create a media file name
    String timeStamp = new SimpleDateFormat("ddMMyyyy_HHmm").format(new Date());
    String mImageName = timeStamp + "_" + name + ".jpg";
    File mediaFile;
    mediaFile = new File(mediaStorageDir.getPath() + File.separator + mImageName);
    return mediaFile;
}

From source file:Main.java

/**
 * Creates a media file in the {@code Environment.DIRECTORY_PICTURES} directory. The directory
 * is persistent and available to other applications like gallery.
 *
 * @param type Media type. Can be video or image.
 * @return A file object pointing to the newly created file.
 *///from  w ww  .ja  v a2  s. com
public static File getOutputMediaFile(int type) {
    // To be safe, you should check that the SDCard is mounted
    // using Environment.getExternalStorageState() before doing this.
    if (!Environment.getExternalStorageState().equalsIgnoreCase(Environment.MEDIA_MOUNTED)) {
        return null;
    }
    // Edit: store in DIRECTORY_DCIM
    File mediaStorageDir = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM),
            "CameraSample");
    // 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("CameraSample", "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:Main.java

static String getDefaultMediaDirectory(int type) {
    String dirType = new String();
    switch (type) {
    case 0:/*  www.j av a  2 s .c om*/
        dirType = Environment.DIRECTORY_MUSIC;
        break;
    case 1:
        dirType = Environment.DIRECTORY_MOVIES;
        break;
    case 2:
        dirType = Environment.DIRECTORY_DCIM;
        break;
    default:
        break;
    }

    File path = new File("");
    if (type == 3) {
        // There is no API for knowing the standard location for sounds
        // such as voice recording. Though, it's typically in the 'Sounds'
        // directory at the root of the external storage
        path = new File(
                Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + "Sounds");
    } else {
        path = Environment.getExternalStoragePublicDirectory(dirType);
    }

    path.mkdirs(); // make sure the directory exists

    return path.getAbsolutePath();
}

From source file:com.lge.osclibrary.OSCCommandsExecute.java

/**
 * Return location of downloaded files from friends device in local storage
 *
 * @return local directory uri for friends camera
 *//*from ww  w  .j  a  va 2  s .c om*/
public static String getFileLocation() {
    String dcimDirectory = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM).toString();

    return dcimDirectory + "/friendsCameraSample";
}