0

in my application I need to capture some images and save them in a folder with the option to rename it. Thanks for your help and sorry for my bad English ..... and I tried that but it does not work, it saves just one image even snap more photos, why? thanks :D

public class TestPress extends Activity  {
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.prova);
        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);

                Uri uriSavedImage=Uri.fromFile(new File("/sdcard/CameraTest/flashCropped.png"));
                camera.putExtra(MediaStore.EXTRA_OUTPUT, uriSavedImage);
                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, CameraActivity.class);
                startActivity(next);
            }
        });
    }
}
Mats Fredriksson
  • 19,783
  • 6
  • 37
  • 57
echo_mongi
  • 41
  • 2
  • 7
  • possible duplicate of [Android Camera - Save image into a new folder in SD Card](http://stackoverflow.com/questions/8588838/android-camera-save-image-into-a-new-folder-in-sd-card) – alex Aug 19 '13 at 23:51
  • Please be a bit specific while asking question. There a lot of link on `how to capture image by camera` and `how to save bitmap in internal/external storage`. Browse them. – Kaidul Aug 19 '13 at 23:51
  • I'm sorry, they are more specific, I need to capture pictures with the camera after saving these photos in a folder can be renamed (folder) in memory of the device after you pressed a button. – echo_mongi Aug 20 '13 at 00:05
  • Hello and welcome to Stack Overflow. Please make sure your question is specific and unique and always google before you post. There already are questions asking about how to use the camera on Android. – WolfLink Aug 20 '13 at 00:07

1 Answers1

1
    private void doTakePhotoAction() {

    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    // 创建目录
    File fileDir = new File(Environment.getExternalStorageDirectory()
            + "/zuijiao");
    if (!fileDir.exists()) {
        fileDir.mkdirs();
    }
    // 拍照后的路径
    imagePath = Environment.getExternalStorageDirectory() + "/zuijiao/"
            + System.currentTimeMillis() + ".jpg";
    carmeraFile = new File(imagePath);
    imageCarmeraUri = Uri.fromFile(carmeraFile);

    intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT,
            imageCarmeraUri);

    try {
        intent.putExtra("return-data", true);
        startActivityForResult(intent, ACTION_TAKE_CARMERA);
    } catch (ActivityNotFoundException e) {
        // Do nothing for now
    }
}

and pls check the save file length, if length equal 0,you should delete it(some people open the camera but don't take a photo,there will have a empty file,delete it)

    @Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    // TODO Auto-generated method stub
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == ACTION_TAKE_CARMERA) 
    {

    }
}

you can do something after photo taken in this function.

there also have other ways to do this

Su Zhenpeng
  • 224
  • 1
  • 3