Skip to content

Instantly share code, notes, and snippets.

@Gizmodo
Created May 17, 2023 11:54
Show Gist options
  • Save Gizmodo/b3a753ac06f1f4573eda7d8a0e8aafb8 to your computer and use it in GitHub Desktop.
Save Gizmodo/b3a753ac06f1f4573eda7d8a0e8aafb8 to your computer and use it in GitHub Desktop.
Camera and document
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