Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to save images from Camera in Android to specific folder?

Basically, what I want to do is allow the user to make their own folder and then go to an activity that contains a button to launch the camera.

From there I want to be able to launch the camera and save the camera images into the newly created folder.

I am having trouble with last part of saving the camera images into the newly created folder.

Here is my Code :

 public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    Button b = (Button) findViewById(R.id.button1);
    b.setOnClickListener(new OnClickListener() {


        EditText text = (EditText)findViewById(R.id.editText1); 
        EditText text2 = (EditText)findViewById(R.id.editText2);



        @Override
        public void onClick(View v) {

            final String name = text.getText().toString();
            final String placeName = text2.getText().toString(); 

            String place = placeName.substring(0,3);
            String direct = name + place ;

            File folder = new File("/sdcard/CameraTest/" + direct + "/");
            folder.mkdirs();

            Intent myIntent = new Intent(CameraTestActivity.this, Press.class);
            myIntent.putExtra("key", "/sdcard/CameraTest/" + direct + "/");
            startActivity(myIntent);

        }
    });

From here I transition into this activity:

public class Press extends Activity {


    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.afterenter);
        final String direct = this.getIntent().getStringExtra("key");


        // TODO Auto-generated method stub
        Button p = (Button) findViewById(R.id.button2);
        p.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {

                Intent camera= new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);

                startActivityForResult(camera, 1);

            }
        });



    Button np = (Button) findViewById(R.id.button3);
    np.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent next = new Intent(Press.this, CameraTestActivity.class);
            startActivity(next);
        }
    });         
    }
}

Please tell me how to save the images from the camera into the newly created folder.

I want the user to be able to take several pictures and then save these several pictures into that specific folder.

like image 937
Adi Ten Avatar asked Sep 01 '11 05:09

Adi Ten


People also ask

How do I save pictures to a folder?

Right-click the illustration that you want to save as a separate image file, and then click Save as Picture. In the Save as type list, select the file format that you want. In the File name box, type a new name for the picture, or just accept the suggested file name. Select the folder where you want to store the image.

What is the best camera app to save pictures in specific folders?

I like "piktures" by Diune. Most camera apps allow you to save the pictures in any folder, but the folder has to exist first. So you can create the folder, then point the app to it, and take your pictures.


1 Answers

add this code before calling camera activity,

Uri uriSavedImage=Uri.fromFile(new File("/sdcard/flashCropped.png"));
camera.putExtra(MediaStore.EXTRA_OUTPUT, uriSavedImage);
startActivityForResult(camera, 1);
like image 70
ilango j Avatar answered Oct 05 '22 09:10

ilango j