Created
May 1, 2020 23:45
-
-
Save wajahatkarim3/1cadd3b98bb818d877ac545078185634 to your computer and use it in GitHub Desktop.
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
// TakePicture Contract Registration | |
private val takePicture = registerForActivityResult(ActivityResultContracts.TakePicture()) {bitmap -> | |
bitmap?.let { | |
imageView.setImageBitmap(bitmap) | |
} | |
} | |
// Calling the takePicture contract | |
captureButton.setOnClickListener { | |
var imageUri: Uri? = null | |
takePicture(imageUri) | |
} |
Please follow this answer:
val directory = File(context.filesDir, "camera_images")
if (!directory.exists()) {
directory.mkdirs()
}
val file = File(directory, "${Calendar.getInstance().timeInMillis}.png")
Uri uri = FileProvider . getUriForFile (this, getApplicationContext().getPackageName()+".provider", file)
ActivityResultLauncher<Uri> mGetContent =
registerForActivityResult (
new ActivityResultContracts.TakePicture (),
new ActivityResultCallback < Boolean >() {
@Override
public void onActivityResult(Boolean result) {
// Use your 'uri' here
}
})
mGetContent.launch(uri)
Sources:
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
in the update takepitcure launch require uri? how to pass as i passed it return null in that uri