Intent m_intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
File file = new File(Environment.getExternalStorageDirectory(), "MyPhoto.jpg");
Uri uri = FileProvider.getUriForFile(this, this.getApplicationContext().getPackageName() + ".provider", file);
m_intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, uri);
startActivityForResult(m_intent, CAMERA_REQUEST);
-
Photo got clicked successfully but Resutl of Activity returns 0DeGM Narmadapuram– DeGM Narmadapuram2023年08月06日 00:22:58 +00:00Commented Aug 6, 2023 at 0:22
-
Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking.Community– Community Bot2023年08月07日 05:56:34 +00:00Commented Aug 7, 2023 at 5:56
1 Answer 1
DeGM Narmadapuram, Here I am sharing full code for clicking image from Camera and show it to imageview.
try {
val chooserIntent = Intent(MediaStore.ACTION_IMAGE_CAPTURE)
captureFile = createImageFile(this@TIDProcessActivity)
if (captureFile != null) {
val photoURI = FileProvider.getUriForFile(
this@TIDProcessActivity,
"com.abcdemo.fileprovider",
captureFile
)
chooserIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI)
}
startActivityIntent.launch(chooserIntent)
} catch (e: Exception) {
Log.e("TAG", "onCreate: " + e.message)
}
From this method you can capture picture and that picture has URI already created while clicking image so when you get result you can directly show image from this URI like below :
var startActivityIntent = registerForActivityResult<Intent, ActivityResult>(
ActivityResultContracts.StartActivityForResult()
) {
val bitmap = BitmapFactory.decodeFile(captureFile.absolutePath)
if (bitmap != null) {
val fileName = System.currentTimeMillis().toString()
Glide.with(this).load(bitmap).into(binding.zeroTokenImagePath)
}
}
Sign up to request clarification or add additional context in comments.
Comments
default