Java tutorial
//package com.java2s; import java.io.File; import java.text.SimpleDateFormat; import java.util.Date; import android.content.Context; import android.net.Uri; import android.util.Log; public class Main { public static final int MEDIA_TYPE_IMAGE = 1; public static final int MEDIA_TYPE_AUDIO = 2; public static Uri getOutputMediaFileUri(int type, Context c) { return Uri.fromFile(getOutputMediaFile(type, c)); } public static File getOutputMediaFile(int type, Context c) { File mediaStorageDir = new File(c.getApplicationContext().getExternalFilesDir(null).getAbsolutePath()); // Create the storage directory if it does not exist if (!mediaStorageDir.exists()) { if (!mediaStorageDir.mkdirs()) { Log.d("MyCameraApp", "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_AUDIO) { mediaFile = new File(mediaStorageDir.getPath() + File.separator + "VID_" + timeStamp + ".3gp"); } else { return null; } return mediaFile; } }