Java tutorial
//package com.java2s; import java.io.File; import android.app.Activity; import android.content.Intent; import android.net.Uri; import android.os.Environment; import android.provider.MediaStore; public class Main { public static final int REQUEST_TAKE_PICTURE_SELF_CENTER = 4; private static File mAvatar; private static Uri mAvatarUri; private static Activity mActivity; public static final String TEMP_IMG_PATH = Environment.getExternalStorageDirectory() + "/yourName/temp"; public static void getCameraFromSelfCenter(Activity activity, boolean openFrontCamera) { initData(activity); Intent intent = new Intent("android.media.action.IMAGE_CAPTURE"); Intent intent_camera = activity.getPackageManager().getLaunchIntentForPackage("com.android.camera"); if (intent_camera != null) { intent.setPackage("com.android.camera"); } if (openFrontCamera) { intent.putExtra("android.intent.extras.CAMERA_FACING", 1); } intent.putExtra(MediaStore.EXTRA_OUTPUT, mAvatarUri); activity.startActivityForResult(intent, REQUEST_TAKE_PICTURE_SELF_CENTER); } private static void initData(Activity activity) { mActivity = activity; File mFile = new File(Environment.getExternalStorageDirectory() + "/yourName"); if (!mFile.exists()) mFile.mkdirs(); mAvatar = new File(TEMP_IMG_PATH); if (mAvatar.exists()) mAvatar.delete(); mAvatarUri = Uri.fromFile(mAvatar); } }