15

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.

SAYE
  • 1,247
  • 2
  • 20
  • 47
Adi Ten
  • 163
  • 1
  • 1
  • 5

3 Answers3

14

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);
ilango j
  • 5,967
  • 2
  • 28
  • 25
0

You should add the file location to the image capture intent. For example:

camera.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, [file location]);

Take a look here

Lior Ohana
  • 3,467
  • 4
  • 34
  • 49
0

Try out this....

path = Environment.getExternalStorageDirectory() + "/photo1.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_ACTIVITY);

and you haven't implemented onActivityResult() Try out this may help you.

public void onActivityResult(int requestCode, int resultCode, Intent data) {
    System.gc();
    if (requestCode == CAPTURE_IMAGE_ACTIVITY) {
        if (resultCode == Activity.RESULT_OK) {
            try {
                // Call function MakeFolder to create folder structure if
                // its not created
                if(imageBitmap != null) {
                    imageBitmap = null;
                    imageBitmap.recycle();
                }
                MakeFolder();
                // Get file from temp1 file where image has been stored
                BitmapFactory.Options options = new BitmapFactory.Options();
                options.inSampleSize = 3;
                imageBitmap = BitmapFactory.decodeFile(path, options);
                imgForPhotograph.setImageBitmap(imageBitmap);
                isImageTaken = true;
                // Name for image
                IMAGEPATH = getString(R.string.chassisImage)
                        + System.currentTimeMillis();
                SaveImageFile(imageBitmap,IMAGEPATH);
            } catch (Exception e) {
                Toast.makeText(this, "Picture Not taken",
                                Toast.LENGTH_LONG).show();
                e.printStackTrace();
            }
        }
    }
Zoe
  • 27,060
  • 21
  • 118
  • 148
Richa
  • 3,165
  • 1
  • 22
  • 26
  • 1
    CAPTURE_IMAGE_ACTIVITY is nothing but a integer, you can use simple interger value of your choice say 99/7/67 anything. It is used to check for the request code. For example 1 activity can start many other activities but every request should have unique request code, which can be checked on returning of every activity inside onActivityResult in your main activity.Check request code to know which activity has returned. – Kuntal Basu Nov 27 '13 at 16:19