Java tutorial
//package com.java2s; //License from project: Apache License import android.annotation.SuppressLint; import android.os.Environment; import java.io.File; import java.io.IOException; import java.text.SimpleDateFormat; import java.util.Date; public class Main { public static final String JPEG_EXTENSION = ".jpg"; @SuppressLint("SimpleDateFormat") public static 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 image = File.createTempFile(imageFileName, /* prefix */ JPEG_EXTENSION, /* suffix */ storageDir /* directory */ ); return image; } }