2

I would like to take multiple photos via Intent. I know how to make intent for taking just one image, but what if I would like to take e.g. 10 photos?

static final int REQUEST_IMAGE_CAPTURE = 1;

private void dispatchTakePictureIntent() {
  Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
  if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
      startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE);
  }
}

Trivial solution is to make another intent after result but I think there must be better solution, isn't there?

Krivers
  • 1,986
  • 2
  • 22
  • 45

2 Answers2

2

You have to do something by using some trick, one of the question asked on the stackoverflow will help you, see this link second check this link these two links will surely help you. the second link recomend this code

Intent intent = new Intent(
    MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA);
this.startActivity(intent);
Community
  • 1
  • 1
Naveed Ahmad
  • 6,627
  • 2
  • 58
  • 83
  • Thank you. I have one more question, do you know, how can I get taken images? – Krivers Aug 22 '14 at 09:36
  • you have to keep a uri where the taken picture saves... Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); String fileName = TravellerUtils.generateUniqueID() + IMAGE_FILE_EXT; File file = new File(Environment.getExternalStorageDirectory(), TravellerConstants.IMAGE_PATH + fileName); Uri outputFileUri = Uri.fromFile(file); intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri); startActivityForResult(intent, TAKE_PICTURE); dont know exact solution but you can get idea now – Naveed Ahmad Aug 22 '14 at 10:07
  • why you reomved Question Selection? I have answered what you asked? – Naveed Ahmad Aug 22 '14 at 10:08
  • I am sorry, my mistake :) Thank you so much. I will try it. – Krivers Aug 22 '14 at 10:13
1

In my case I had to use MediaStore.ACTION_IMAGE_CAPTURE in order to disable selecting image from the phone gallery.

In order to achieve "similar" behaviour with taking several pictures I was starting next camera intent directly from onActivityResult while processing recently taken photo in background.

Code looks like this:

...
    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)
        if (requestCode != REQUEST_IMAGE_CAPTURE) {
            return
        }
        if (resultCode == Activity.RESULT_CANCELED) {
            Timber.d("Taking image was cancelled")
            return
        }
        if (resultCode == Activity.RESULT_OK) {
            lastTakenPhotoData?.let {
                handlePhotoTaken(it)
                startCameraIntent()
            }
        }
    }
...

    private fun handlePhotoTaken(...) {
        disposable.add(
            Single.fromCallable { compressPhotoTaken(data) }
                    .subscribeOn(Schedulers.computation())
                    .observeOn(AndroidSchedulers.mainThread()).subscribe { _ ->
                        //update UI with processed photo
                    }
        )
    }
...
    private fun compressTakenPhoto(...) {
        //rotate, compress, save taken photo to the local file if needed
        //this part was taking quite a lot of time, so it is better to do it in background
    }

Sergii N.
  • 315
  • 3
  • 10