Android how to save captured image to phone gallery

I have two activities. In one action, I have an ImageView button and a camera button. When I click the camera button, it goes into another activity, where there are two Capture buttons, and the other is the Select button. When I press the capture button, it captures the image. But the question is how to save this capture image in the gallery. And after clicking the "Select" button, the captured image should be displayed on the 1st ImageView activity. How can i do this.

+4
source share
3 answers

try it.

 String path = Environment.getExternalStorageDirectory() + "/CameraImages/example.jpg"; File file = new File(path); Uri outputFileUri = Uri.fromFile( file ); Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE ); intent.putExtra( MediaStore.EXTRA_OUTPUT, outputFileUri ); startActivityForResult( intent, CAPTURE_IMAGE ); 

your image will be saved in this place "sdcard / CameraImages / example.jpg"

+1
source

So I did it. Image saved in minutes + seconds + .jpg to sdcard:

 final static private int NEW_PICTURE = 1; private String mCameraFileName; ImageButton Edit = (ImageButton) findViewById(R.id.internetbrowser4); Edit.setOnClickListener(new OnClickListener() { public void onClick(View v) { Intent intent = new Intent(); // Picture from camera intent.setAction(MediaStore.ACTION_IMAGE_CAPTURE); // This is not the right way to do this, but for some reason, having // it store it in // MediaStore.Images.Media.EXTERNAL_CONTENT_URI isn't working right. Date date = new Date(); DateFormat df = new SimpleDateFormat("-mm-ss"); String newPicFile = "Bild"+ df.format(date) + ".jpg"; String outPath = "/sdcard/" + newPicFile; File outFile = new File(outPath); mCameraFileName = outFile.toString(); Uri outuri = Uri.fromFile(outFile); intent.putExtra(MediaStore.EXTRA_OUTPUT, outuri); startActivityForResult(intent, NEW_PICTURE); } }); public void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == NEW_PICTURE) { // return from file upload if (resultCode == Activity.RESULT_OK) { Uri uri = null; if (data != null) { uri = data.getData(); } if (uri == null && mCameraFileName != null) { uri = Uri.fromFile(new File(mCameraFileName)); } File file = new File(mCameraFileName); if (!file.exists()) { file.mkdir(); } } }} } 
+1
source

All Articles