79178065

Date: 2024-11-11 14:42:12
Score: 1
Natty:
Report link

I'm sorry, the correct path is "/data/data/com.alberto.autocontrol2/files" (taken from Android Studio's device explorer). And this is the code to take the photo from the camera and save it to the device storage. The code is taken from a separate "PantallaRegistrarVehiculo.kt" screen (VehicleRegistrationScreen.kt in English):

 val lanzador = rememberLauncherForActivityResult(
  contract = ActivityResultContracts.TakePicturePreview()
) { bitmap: Bitmap? ->
  if (bitmap != null) {
     val file = File(contexto.filesDir, 
"${viewModel.listaVehiculos.value.size}.jpg") // Or .png
     try {
        FileOutputStream(file).use { out ->
           bitmap.compress(Bitmap.CompressFormat.JPEG, 100, out) // 
Or PNG
        }
        imageBitmap = bitmap.asImageBitmap()
     } catch (e: IOException) {
        e.printStackTrace()
     }
  }
}
Reasons:
  • Contains signature (1):
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (0.5):
Posted by: Alberto