Default Camera Issue Only Honor Magic Pro 7

1 view
Skip to first unread message

Qasim Abdani

unread,
1:08 AM (9 hours ago) 1:08 AM
to Android CameraX Discussion Group

I have tested the app on multiple device brands, and it works 100% correctly on all of them. The issue occurs only on the Honor Magic Pro 7, which is being used by my client.

On this device, the camera opens normally, captures the picture, and shows the image preview. However, when the user clicks the tick/confirm button, the app turns into a blank white screen.

There is no crash reported in Firebase Crashlytics, and no error logs are generated, so I’m unable to identify the cause of the issue. 
------------------------------------------------------------------
val imageChooserLauncher = rememberLauncherForActivityResult(contract = StartActivityForResult()) { resultt ->
if (resultt.resultCode == RESULT_OK) {
val data = resultt.data
// ------------------ Multiple videos/images from gallery ------------------
if (data?.clipData != null) {
val clipData = data.clipData
val videoUris = mutableListOf<Uri>()
for (i in 0 until clipData!!.itemCount) {
videoUris.add(clipData.getItemAt(i).uri)
}

videoUris.forEach { b ->
val updatedMediaList = (result.value ?: emptyList()).toMutableList()
val uri = getFileAbsolutePath1(
applicationContext,
b,
EnumCRItemType.IMAGE.value
)
updatedMediaList.add(
MMedia(
type = EnumCRItemType.IMAGE.value,
key = uri
)
)
result.value = updatedMediaList
formField.media = updatedMediaList
if (formField.type == EnumCRItemType.FILE.value) {
formField.values?.add(
FieldValue(
text = EnumCRItemType.IMAGE.value,
value = uri
)
)
}
}
reportViewModel.updateFormData(formSection)
}
// ------------------ Single video/image from gallery ------------------
else if (data?.data != null) {
val singleVideoUri = data.data!!
val updatedMediaList = (result.value ?: emptyList()).toMutableList()
val uri = getFileAbsolutePath1(
applicationContext,
singleVideoUri,
EnumCRItemType.IMAGE.value
)
updatedMediaList.add(
MMedia(
type = EnumCRItemType.IMAGE.value,
key = uri
)
)
result.value = updatedMediaList
formField.media = updatedMediaList
if (formField.type == EnumCRItemType.FILE.value) {
formField.values?.add(
FieldValue(
text = EnumCRItemType.IMAGE.value,
value = uri
)
)
}
reportViewModel.updateFormData(formSection)
}

else if (data == null || data.data == null) {
Handler(Looper.getMainLooper()).postDelayed({
cameraImageUri?.let { uri ->

// try {
//
// contentResolver.takePersistableUriPermission(
// uri,
// Intent.FLAG_GRANT_READ_URI_PERMISSION or
// Intent.FLAG_GRANT_WRITE_URI_PERMISSION
// )
// }catch(e:Exception){}


val updatedMediaList = (result.value
?: emptyList()).toMutableList()
val path = getFileAbsolutePath1(
applicationContext,
uri,
EnumCRItemType.IMAGE.value
)
updatedMediaList.add(
MMedia(
type = EnumCRItemType.IMAGE.value,
key = path
)
)
result.value = updatedMediaList
formField.media = updatedMediaList

if (formField.type == EnumCRItemType.FILE.value) {
formField.values?.add(
FieldValue(
text = EnumCRItemType.IMAGE.value,
value = path
)
)
}
reportViewModel.updateFormData(formSection)


}
},300)

}

}
}

------------------------------------------------------------------
val uri = CommonMethods.createCameraImageFile(applicationContext)
cameraImageUri = uri // Save to the 'rememberSaveable' state

val captureIntent = Intent(MediaStore.ACTION_IMAGE_CAPTURE).apply {
putExtra(MediaStore.EXTRA_OUTPUT, uri)

clipData = ClipData.newUri(contentResolver, "camera", uri)

addFlags(
Intent.FLAG_GRANT_READ_URI_PERMISSION or
Intent.FLAG_GRANT_WRITE_URI_PERMISSION or
Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION
)
}

val pickIntent = Intent(Intent.ACTION_GET_CONTENT).apply {
type = "image/*"
putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true)
addCategory(Intent.CATEGORY_OPENABLE)
}

val chooserIntent = Intent.createChooser(pickIntent, "Select or Capture Image").apply {
putExtra(Intent.EXTRA_INITIAL_INTENTS, arrayOf(captureIntent))
// Standard flags for the chooser itself
addFlags(
Intent.FLAG_GRANT_READ_URI_PERMISSION or
Intent.FLAG_GRANT_WRITE_URI_PERMISSION or
Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION
)
}

imageChooserLauncher.launch(chooserIntent)


------------------------------------------------------------------
var cameraImageUri by rememberSaveable { mutableStateOf<Uri?>(null) }

------------------------------------------------------------------

fun getFileAbsolutePath1(
context: Context,
uri: Uri,
type: String
): String {

val resolver = context.contentResolver
val inputStream = resolver.openInputStream(uri) ?: return ""

val directory =
if (type == EnumCRItemType.IMAGE.value)
Environment.DIRECTORY_PICTURES
else
Environment.DIRECTORY_DOCUMENTS

val extension = when (type) {
EnumCRItemType.VIDEO.value -> ".mp4"
EnumCRItemType.DOCUMENT.value -> ".pdf"
else -> ".jpg"
}

val file = File(
context.getExternalFilesDir(directory),
"${System.currentTimeMillis()}$extension"
)

FileOutputStream(file).use { output ->
inputStream.use { input ->
input.copyTo(output)
}
}

return file.absolutePath
}

------------------------------------------------------------------

fun createCameraImageFile(context: Context): Uri {
val file = File(
context.getExternalFilesDir(Environment.DIRECTORY_PICTURES),
"camera_image_${System.currentTimeMillis()}.jpg"
)

return FileProvider.getUriForFile(
context,
"${context.packageName}.fileprovider",
file
)
}


------------------------------------------------------


<provider
android:name="androidx.core.content.FileProvider"
android:authorities="com.krank.inspeq.fileprovider"
android:exported="false"
android:grantUriPermissions="true"
tools:replace="android:authorities">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths"
/>
</provider>

-----------------------------------------------------

<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">

<!-- REQUIRED for Honor / Huawei camera -->
<external-files-path
name="images"
path="Pictures/" />

<!-- Optional (safe to keep) -->
<cache-path
name="cache"
path="." />

</paths>













Reply all
Reply to author
Forward
0 new messages