Android examples for Graphics:Image File
create Image File for Album based on date and time
//package com.java2s; import java.io.File; import java.io.IOException; import java.text.SimpleDateFormat; import java.util.Date; import android.os.Environment; import android.util.Log; public class Main { private final static String TAG = "Camera4ActivityUtil"; private static final String JPEG_FILE_PREFIX = "IMG_"; private static final String JPEG_FILE_SUFFIX = ".jpg"; private static final String CAMERA_DIR = "/dcim/"; static private File createImageFile() throws IOException { // Create an image file name String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss") .format(new Date()); String imageFileName = JPEG_FILE_PREFIX + timeStamp + "_"; File albumF = getAlbumDir(); File imageF = File.createTempFile(imageFileName, JPEG_FILE_SUFFIX, albumF);// w w w . ja v a 2s .co m return imageF; } static private File getAlbumDir() { File storageDir = null; if (Environment.MEDIA_MOUNTED.equals(Environment .getExternalStorageState())) { storageDir = getAlbumStorageDir(getAlbumName()); if (storageDir != null) { if (!storageDir.mkdirs()) { if (!storageDir.exists()) { Log.d(TAG, "failed to create directory"); return null; } } } } else { Log.v(TAG, "External storage is not mounted READ/WRITE."); } return storageDir; } static private File getAlbumStorageDir(String albumName) { return new File(Environment.getExternalStorageDirectory() + CAMERA_DIR + albumName); } static private String getAlbumName() { return "MenuPhoto"; } }