Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private fun startCameraIntent() {
- Chat.stopCameraX()
- Intent(MediaStore.ACTION_IMAGE_CAPTURE).also { takePictureIntent ->
- takePictureIntent.resolveActivity(requireContext().packageManager)?.also {
- val photoFile: File? = try {
- createImageFile()
- } catch (exception: IOException) {
- logger.e("Failed to get image file: ${exception.message}")
- displayErrorMessage(getString(R.string.cant_create_photo))
- null
- }
- photoFile?.also { file ->
- val photoURI: Uri = FileProvider.getUriForFile(
- requireContext(),
- requireContext().applicationContext.packageName + ".provider",
- file
- )
- takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI)
- startActivityForResult(takePictureIntent, CAMERA_ACTIVITY_FOR_RESULT)
- }
- }
- }
- }
- private fun createImageFile(): File? {
- val timeStamp =
- SimpleDateFormat("yyyyMMddHHmmss", Locale.getDefault()).format(Date())
- val storageDir = context?.getExternalFilesDir(Environment.DIRECTORY_PICTURES)
- return File.createTempFile(
- "JPEG_${timeStamp}_",
- ".jpg",
- storageDir
- ).also {
- cameraImageUri = Uri.fromFile(it)
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement