Change theme
Help
Press space for more information.
Show links for this issue (Shortcut: i, l)
Copy issue ID
Previous Issue (Shortcut: k)
Next Issue (Shortcut: j)
Sign in to use full features.
Vote: I am impacted
Notification menu
Refresh (Shortcut: Shift+r)
Go home (Shortcut: u)
Pending code changes (auto-populated)
View issue level access limits(Press Alt + Right arrow for more information)
Unintended behavior
View staffing
Description
CAMERAX VERSION: 1.2.3
CAMERA APPLICATION NAME AND VERSION: (Settings > Apps > (app name) > version) Android version 13
ANDROID OS BUILD NUMBER: (Settings > About > Build number) CPH2487_13.1.0.540(EX01)
DEVICE NAME: OnePlus 11R 5G
DESCRIPTION:
STEPS TO REPRODUCE:
1. Camera change front.
2. Camera capture photo
3. ImageCapture.OnImageSavedCallback -> override fun onError(ex: ImageCaptureException) { }
OBSERVED RESULTS:
EXPECTED RESULTS:
1. Camera change front.
2. Camera capture photo
3. ImageCapture.OnImageSavedCallback -> onImageSaved(output: ImageCapture.OutputFileResults){ }
REPRODUCIBILITY: (5 of 5, 1 of 100, etc)
ADDITIONAL INFORMATION:
CODE FRAGMENTS (this will help us troubleshoot your issues):
ImageCapture.OnImageSavedCallback { override fun onError(exc: ImageCaptureException) { } }
Photo capture error
Error message : No flash unit
androidx.camera.core.ImageCaptureException: No flash unit
Code
//startCamera()
private fun startCamera() {
val cameraProviderFuture = ProcessCameraProvider.getInstance(this)
cameraProviderFuture.addListener({
// Used to bind the lifecycle of cameras to the lifecycle owner
cameraProvider = cameraProviderFuture.get()
// Select lensFacing depending on the available cameras
mLensFacing = when {
hasBackCamera() -> CameraSelector.LENS_FACING_BACK
hasFrontCamera() -> CameraSelector.LENS_FACING_FRONT
else -> throw IllegalStateException("Back and front camera are unavailable")
}
mFlashMode = when {
hasFlashMode() -> ImageCapture.FLASH_MODE_OFF
else -> NO_FLASH
}
bindCameraUseCases()
}, ContextCompat.getMainExecutor(this))
}
//bindCameraUseCases
private fun bindCameraUseCases() {
// Preview
val preview = Preview.Builder()
.build()
.also {
it.setSurfaceProvider(binding.previewView.surfaceProvider)
}
val recorder = Recorder.Builder()
.setQualitySelector(QualitySelector.from(Quality.HIGHEST,
FallbackStrategy.higherQualityOrLowerThan(Quality.SD)))
.build()
videoCapture = VideoCapture.withOutput(recorder)
//imageCapture = ImageCapture.Builder().build()
imageCapture = ImageCapture.Builder()
.apply {
if (mFlashMode != NO_FLASH)
setFlashMode(mFlashMode)
}.build()
// Select back camera as a default
//val cameraSelector = CameraSelector.DEFAULT_BACK_CAMERA
val cameraSelector = CameraSelector.Builder().apply {
requireLensFacing(mLensFacing)
}.build()
Log.d("###","### Camera mLensFacing :"+mLensFacing)
Log.d("###","### Camera mFlashMode :"+mFlashMode)
try {
// Unbind use cases before rebinding
cameraProvider?.unbindAll()
// Bind use cases to camera
mCamera = cameraProvider?.bindToLifecycle(
this, cameraSelector, preview, imageCapture, videoCapture)
} catch(exc: Exception) {
Log.e(TAG, "Use case binding failed", exc)
}
}
//take photo
private fun takePhoto() {
Log.d("###","### takePhoto()")
enableDisableAllButtons(false)
// Get a stable reference of the modifiable image capture use case
val imageCapture = imageCapture ?: return
// Create time stamped name and MediaStore entry.
val name = SimpleDateFormat(FILENAME_FORMAT, Locale.US)
.format(System.currentTimeMillis()) + ".jpg"
val contentValues = ContentValues().apply {
put(MediaStore.MediaColumns.DISPLAY_NAME, name)
put(MediaStore.MediaColumns.MIME_TYPE, "image/jpeg")
if(Build.VERSION.SDK_INT > Build.VERSION_CODES.P) {
put(MediaStore.Images.Media.RELATIVE_PATH, "Pictures/Tournament_Photos")
}
}
val photoFile = File(mOutputDirectory, name)
val metadata = ImageCapture.Metadata().apply {
isReversedHorizontal = mLensFacing == CameraSelector.LENS_FACING_FRONT
}
val outputOptions = ImageCapture.OutputFileOptions.Builder(photoFile)
.apply {
setMetadata(metadata)
}.build()
// Set up image capture listener, which is triggered after photo has
// been taken
imageCapture.takePicture(
outputOptions,
ContextCompat.getMainExecutor(this),
object : ImageCapture.OnImageSavedCallback {
override fun onError(exc: ImageCaptureException) {
Log.e(TAG, "Photo capture failed: ${exc.message}", exc)
Log.d("###","### Photo capture failed:"+exc.message)
Log.d("###","### 1Photo capture failed:"+exc)
}
override fun
onImageSaved(output: ImageCapture.OutputFileResults){
val msg = "Photo capture succeeded: ${output.savedUri}"
//Toast.makeText(baseContext, msg, Toast.LENGTH_SHORT).show()
Log.d(TAG, msg)
if (ActivityCompat.checkSelfPermission(
this@CameraKitKotlinActivity,
Manifest.permission.ACCESS_FINE_LOCATION
) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(
this@CameraKitKotlinActivity,
Manifest.permission.ACCESS_COARSE_LOCATION
) != PackageManager.PERMISSION_GRANTED
) {
// TODoO: Consider calling
// ActivityCompat#requestPermissions
// here to request the missing permissions, and then overriding
// public void onRequestPermissionsResult(int requestCode, String[] permissions,
// int[] grantResults)
// to handle the case where the user grants the permission. See the documentation
// for ActivityCompat#requestPermissions for more details.
return
}
fusedLocationClient.lastLocation.addOnSuccessListener { location ->
if (location != null) {
//mViewModel.savePhoto(photoFile,location)
Toast.makeText(applicationContext, "Photo : "+photoFile, Toast.LENGTH_LONG).show()
enableDisableAllButtons(true)
} else {
Toast.makeText(applicationContext, "Check location permission.", Toast.LENGTH_LONG).show()
}
}
enableDisableAllButtons(true)
}
}
)
}
//toggleFlash()
private fun toggleFlash() {
when (mFlashMode) {
ImageCapture.FLASH_MODE_OFF -> {
Log.d("###","### FLASH_MODE_ON")
mFlashMode = ImageCapture.FLASH_MODE_ON
//binding.flashBtn?.setImageResource(R.drawable.baseline_flash_off_white_36)
binding.flashBtn?.setImageResource(R.drawable.baseline_flash_on_white_36)
}
ImageCapture.FLASH_MODE_ON -> {
Log.d("###","### FLASH_MODE_AUTO")
mFlashMode = ImageCapture.FLASH_MODE_AUTO
//binding.flashBtn.setImageResource(R.drawable.baseline_flash_on_white_36)
binding.flashBtn.setImageResource(R.drawable.baseline_flash_auto_white_36)
}
ImageCapture.FLASH_MODE_AUTO -> {
Log.d("###","### FLASH_MODE_OFF")
mFlashMode = ImageCapture.FLASH_MODE_OFF
//binding.flashBtn.setImageResource(R.drawable.baseline_flash_auto_white_36)
binding.flashBtn.setImageResource(R.drawable.baseline_flash_off_white_36)
}
}
// Re-bind use cases to include changes
bindCameraUseCases()
}
// change camera
mLensFacing = if (CameraSelector.LENS_FACING_FRONT == mLensFacing) {
CameraSelector.LENS_FACING_BACK
} else {
CameraSelector.LENS_FACING_FRONT
}
bindCameraUseCases()
}