Following code worked for most of the devices that were important to me:
val targetPackage = getMediaCaptureIntent(imageUri).resolveActivity(packageManager)
Photo Camera:
fun getMediaCaptureIntent(mediaUri: Uri, targetPackage: String? = null): Intent {
return Intent(MediaStore.ACTION_IMAGE_CAPTURE).apply {
putExtra(MediaStore.EXTRA_OUTPUT, mediaUri)
// Extras for displaying the front camera on most devices
putExtra("com.google.assistant.extra.USE_FRONT_CAMERA", true)
putExtra("android.intent.extra.USE_FRONT_CAMERA", true)
putExtra("android.intent.extras.LENS_FACING_FRONT", 1)
putExtra("android.intent.extras.CAMERA_FACING", 1)
// Extras for displaying the front camera on Samsung
putExtra("camerafacing", "front")
putExtra("previous_mode", "Selfie")
if (targetPackage?.contains("honor", ignoreCase = true) == true) {
// Extras for displaying the front camera on Honor
putExtra("default_camera", "1")
putExtra("default_mode", "com.hihonor.camera2.mode.photo.PhotoMode")
} else {
// Extras for displaying the front camera on Huawei
putExtra("default_camera", "1")
putExtra("default_mode", "com.huawei.camera2.mode.photo.PhotoMode")
}
}
}
Video Camera:
fun getMediaCaptureIntent(mediaUri: Uri, targetPackage: String? = null): Intent {
return Intent(MediaStore.ACTION_VIDEO_CAPTURE).apply {
putExtra(MediaStore.EXTRA_OUTPUT, mediaUri)
// Extras for displaying the front camera on most devices
putExtra("com.google.assistant.extra.USE_FRONT_CAMERA", true)
putExtra("android.intent.extra.USE_FRONT_CAMERA", true)
putExtra("android.intent.extras.LENS_FACING_FRONT", 1)
putExtra("android.intent.extras.CAMERA_FACING", 1)
// Extras for displaying the front camera on Samsung
putExtra("camerafacing", "front")
putExtra("previous_mode", "Video")
if (targetPackage?.contains("honor", ignoreCase = true) == true) {
// Extras for displaying the front camera on Honor
putExtra("default_camera", "1")
putExtra("default_mode", "com.hihonor.camera2.mode.video.VideoMode")
} else {
// Extras for displaying the front camera on Huawei
putExtra("default_camera", "1")
putExtra("default_mode", "com.huawei.camera2.mode.video.VideoMode")
}
}
}