简体   繁体   中英

Taking multiple photos via Intent

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 eg 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?

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);

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
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM