I managed to get photo1.jpg to save in Pictures/mockFolder , which I created on the SD card, here is the code for reference in the future.
public class CameraActivity extends Activity { final int PICTURE_ACTIVITY = 1; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); String dir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES) + "/mockFolder/"; File newdir = new File(dir); newdir.mkdirs(); String file = dir + "photo1.jpg"; File newfile = new File(file); try { newfile.createNewFile(); } catch (IOException e) {} Uri outputFileUri = Uri.fromFile(newfile); Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri); startActivityForResult(cameraIntent, PICTURE_ACTIVITY); } @Override protected void onActivityResult(int requestCode, int resultCode, Intent intent) { super.onActivityResult(requestCode, resultCode, intent); AlertDialog msgDialog; if (resultCode == RESULT_CANCELED) { msgDialog = createAlertDialog("Alert", "Picture was not saved. Please try again.", "OK"); } else { msgDialog = createAlertDialog("Alert", "Picture was saved successfully.", "OK"); } msgDialog.show(); } private AlertDialog createAlertDialog(String title, String msg, String buttonText){ AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this); AlertDialog msgDialog = dialogBuilder.create(); msgDialog.setTitle(title); msgDialog.setMessage(msg); msgDialog.setButton(buttonText, new DialogInterface.OnClickListener(){ @Override public void onClick(DialogInterface dialog, int idx){ finish(); } }); return msgDialog; } public void finish() { super.finish(); } }
Neeta source share