Example usage for android.os Environment DIRECTORY_PICTURES

List of usage examples for android.os Environment DIRECTORY_PICTURES

Introduction

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

Prototype

String DIRECTORY_PICTURES

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

Click Source Link

Document

Standard directory in which to place pictures that are available to the user.

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 ww  .  jav  a2 s .com
        return picturePath + "/nim/";
    } else {
        String picturePath = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM)
                .getAbsolutePath();
        return picturePath + "/nim/";
    }
}

From source file:Main.java

public static File getAvatarPath(Activity activity, String avatrType, String fielName) {
    File dir = activity.getExternalFilesDir(Environment.DIRECTORY_PICTURES);
    //        File dir =Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
    dir = new File(dir, avatrType);
    if (!dir.exists()) {
        dir.mkdirs();/*ww  w . j a v a2s.  co m*/
    }
    File file = new File(dir, fielName);
    return file;
}

From source file:Main.java

public static String getSavePath(Context context) {
    boolean hasSDCard = Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED);
    if (hasSDCard) {
        return Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).toString();
    }/*from ww w .j  a  v a 2  s.  co m*/
    return context.getFilesDir().toString();
}

From source file:Main.java

public static String savePicture(Bitmap bmp, String file) {
    File filepicture = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
    if (file == null || file.equals("")) {
        file = filepicture + "/" + System.currentTimeMillis() + ".jpg";
    }/*from  www  .  j av a  2s. com*/
    FileOutputStream outputStream = null;
    try {
        outputStream = new FileOutputStream(file);
        bmp.compress(Bitmap.CompressFormat.JPEG, 100, outputStream);
    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        if (outputStream != null) {
            try {
                outputStream.flush();
                outputStream.close();
            } catch (IOException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }
            return "";
        }
    } finally {
        if (outputStream != null) {
            try {
                outputStream.flush();
                outputStream.close();
            } catch (IOException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }
        }
    }
    return "file://" + file;
}

From source file:Main.java

public static Uri getOutputMediaFileUri() {
    File mediaStorageDir = new File(
            Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), "Date");
    if (!mediaStorageDir.exists()) {
        if (!mediaStorageDir.mkdirs()) {
            Log.d("Date", "failed to create directory");
            return null;
        }/*from w w w  .  j  a va  2 s .co  m*/
    }

    String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.CHINA).format(new Date());
    File mediaFile = new File(mediaStorageDir.getPath() + File.separator + "IMG_" + timeStamp + ".jpg");

    return Uri.fromFile(mediaFile);
}

From source file:Main.java

private static File getAlbumStorageDir(String albumName) {
    // Get the directory for the user's public pictures directory. 
    File file = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES),
            albumName);/*from  w ww  .  j  ava  2 s  .co  m*/
    if (file.exists()) {
        return file;
    }
    if (!file.mkdirs()) {
        Log.e(TAG, "Directory not created");
    }
    return file;
}

From source file:Main.java

/**
 * Get Image Uri when clicked from Camera
 *
 * @return Uri of clicked Image//from  w w w .java 2 s . c  o m
 */
public static Uri getBitmapUri() {
    File imageStorageDir = new File(
            Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), "CRMnextImages");
    if (!imageStorageDir.exists()) {
        imageStorageDir.mkdirs();
    }
    File file = null;
    try {
        file = File.createTempFile("IMG_" + String.valueOf(System.currentTimeMillis()), ".jpg",
                imageStorageDir);
    } catch (IOException e) {
        e.printStackTrace();
    }
    return Uri.fromFile(file);
}

From source file:Main.java

public static File createFolders() {
    File baseDir;// ww  w  .j  av  a 2s .  c om
    if (android.os.Build.VERSION.SDK_INT < 8) {
        baseDir = Environment.getExternalStorageDirectory();
    } else {
        baseDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
    }
    if (baseDir == null)
        return Environment.getExternalStorageDirectory();
    File aviaryFolder = new File(baseDir, FOLDER_NAME);
    if (aviaryFolder.exists())
        return aviaryFolder;
    if (aviaryFolder.isFile())
        aviaryFolder.delete();
    if (aviaryFolder.mkdirs())
        return aviaryFolder;
    return Environment.getExternalStorageDirectory();
}

From source file:Main.java

public static Uri getOutputImageFileURL() {
    Log.d(LOG_MESSAGE, "external dir:"
            + Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).getAbsolutePath());
    File mediaStorageDir = new File(
            Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), IMAGE_DIRECTORY);
    if (!mediaStorageDir.exists()) {
        if (!mediaStorageDir.mkdirs()) {
            Log.d(LOG_MESSAGE, "failed to create directory");
            return null;
        }//from  w w  w.jav a 2s. com
    }
    String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
    File mediaFile = new File(mediaStorageDir.getAbsolutePath() + File.separator + "IMG_" + timeStamp + ".png");
    return Uri.fromFile(mediaFile);
}

From source file:Main.java

public static File getNewImageFile() 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);
}