SO I am trying to pick a Photo thro camera and show it on the screen. But everytime after picking the image it looks something like this] . It’s just white, there is not content inside.
I have checked the logs, and Image uri is not null, ranther it looks something like
content://com.mifos.mifosxdroid.provider/client_image/client_image1448774659534093575.png
I have already tried this method – Compose – Take Photo with camera and display result not working, but still not working
Here is what I have on compose screen.
var selectedImageUri : Uri? by rememberSaveable { mutableStateOf(null) }
val file = context.createTempImageFile()
val imgUri = FileProvider.getUriForFile(
Objects.requireNonNull(context),
"com.mifos.mifosxdroid" + ".provider",
file
)
val cameraLauncher = rememberLauncherForActivityResult(
contract = ActivityResultContracts.TakePicture(),
onResult = { success ->
if (success) {
selectedImageUri = imgUri
}
}
)
Image(
painter = if (selectedImageUri != null) rememberAsyncImagePainter(selectedImageUri)
else painterResource(id = R.drawable.ic_dp_placeholder ),
contentDescription = null,
modifier = Modifier
.align(Alignment.Center)
.clickable {
cameraLauncher.launch(imgUri)
}
.border(color = DarkGray, width = 2.dp, shape = CircleShape)
.size(80.dp)
.clip(CircleShape)
)
This is another function
fun Context.createTempImageFile(): File {
val imageFileName = "client_image"
return File.createTempFile(
imageFileName, /* prefix */
".png", /* suffix */
externalCacheDir /* directory */
)
}
This is what I have as provider_paths.xml
<?xml version="1.0" encoding="utf-8"?>
<paths>
<external-cache-path name="client_image" path="/" />
</paths>
In the manifest
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="com.mifos.mifosxdroid.provider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/provider_paths" />
</provider>
Can anyone help me with this to fix the issue, I would be grateful, Thanks