开发者

How do I get camera intent to save more than one image?

开发者 https://www.devze.com 2023-02-16 14:28 出处:网络
I have a following question. I\'m using camera intent that starts from a menu button like this case R.id.camera:

I have a following question. I'm using camera intent that starts from a menu button like this

case R.id.camera:           
        final Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        intent.putExtra(MediaStore.EXTRA_OUTPUT,
                Uri.fromFile(getTempFile(this)));           
        startActivityForResult(intent, TAKE_PHOTO_CODE); 
        return true;

This is working just fine and it saves original image (original size which I want).

Than I also have the following code

private File getTempFile(LovneDobe lovneDobe) {
    final File path = new File( Environment.getExternalStorageDirectory(), lovneDobe.getPackageName() );
    sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://"+ Environment.getExternalStorageDirectory())));
      if(!path.exists()){
        path.mkdir();
      }
      return new File(path, "image.jpg");
}

and this code saves the picture on SDcard and it also puts it into my gallery. But the problem I'm facing is that it saves only one picture. When I take another one it overwrites the previous one. And now m开发者_开发百科y question is how can I modify this so that it would save every picture I would take?

Thank in advance to anyone who is willing to help.


I'm pretty sure It's because you are explicitly overriding the file. In your method "getTempFile", you always give the same path and name for every time you call the method. Try having a static counter, for example, to know how many pictures you have done, and in the return, put something like

           return new File(path, "image"+counter+".jpg");
0

精彩评论

暂无评论...
验证码 换一张
取 消