Java tutorial
//package com.java2s; import android.annotation.SuppressLint; import android.content.Context; import android.os.Environment; import android.util.Log; import java.io.File; import java.text.SimpleDateFormat; import java.util.Date; public class Main { public static final int MEDIA_TYPE_IMAGE = 1; public static final int MEDIA_TYPE_AUDIO = 2; /** * Create a File for saving an image or video */ @SuppressLint("SimpleDateFormat") public static File getOutputMediaFile(int type, Context context) { // Create a media file name String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()); File mediaFile = null; if (type == MEDIA_TYPE_IMAGE) { File mediaStorageDir = new File( Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), "StoryCapture"); if (!mediaStorageDir.exists()) { if (!mediaStorageDir.mkdirs()) { Log.d("StoryCapture", "failed to create directory"); return null; } } mediaFile = new File(mediaStorageDir.getPath() + File.separator + "IMG_" + timeStamp + ".jpg"); } else if (type == MEDIA_TYPE_AUDIO) { String fileName = "AUDIO_" + timeStamp + ".3gp"; mediaFile = new File(context.getFilesDir(), fileName); } return mediaFile; } }