Created
May 17, 2023 11:54
-
-
Save Gizmodo/b3a753ac06f1f4573eda7d8a0e8aafb8 to your computer and use it in GitHub Desktop.
Camera and document
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private lateinit var takePicture: ActivityResultLauncher<Uri> | |
private lateinit var chooseDocument: ActivityResultLauncher<Array<String>> | |
private fun attachmentDialog() { | |
val listItems = | |
arrayOf(getString(R.string.capture_image_from_camera), getString(R.string.choose_file)) | |
AlertDialog.Builder(requireContext()) | |
.setItems(listItems) { dialog, which -> | |
when (which) { | |
0 -> { | |
} | |
1 -> { | |
chooseDocument.launch(arrayOf("*/*")) | |
} | |
} | |
} | |
.show() | |
} | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
takePicture = registerForActivityResult(ActivityResultContracts.TakePicture()) { success -> | |
if (success) { | |
attachmentDataAdapter.add( | |
AttachmentData( | |
Attributes( | |
0, "", | |
"", Uri.EMPTY, getFileName(requireContext(), fileUri) ?: "", | |
"", "", "", 0, "", "", "" | |
), 0 | |
) | |
) | |
attachmentItemAdapter.add(fileUri) | |
} | |
} | |
chooseDocument = | |
registerForActivityResult(ActivityResultContracts.OpenMultipleDocuments()) { fileChoosen -> | |
if (fileChoosen != null) { | |
fileChoosen.forEach { file -> | |
// Glide.with(requireContext()).load(file).into(binding.imgPreview) | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment