Skip to content

Update FileChooserResultContract.kt #130

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion samples/MobileBuyIntegration/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ android {
applicationId "com.shopify.checkout_sdk_mobile_buy_integration_sample"
minSdk 23
targetSdk 34
versionCode 33
versionCode 34
versionName "0.0.${versionCode}"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class FileChooserResultContract : ActivityResultContract<FileChooserParams, Uri?
cameraImageUri = FileProvider.getUriForFile(context, "${context.packageName}.provider", photoFile)
val cameraIntent = Intent(MediaStore.ACTION_IMAGE_CAPTURE).apply {
putExtra(MediaStore.EXTRA_OUTPUT, cameraImageUri)
addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION) // Ensures URI can be written
}

val chooserIntent = Intent.createChooser(fileChooserIntent, context.getText(R.string.filechooser_title))
Expand All @@ -64,11 +65,11 @@ class FileChooserResultContract : ActivityResultContract<FileChooserParams, Uri?
}

override fun parseResult(resultCode: Int, intent: Intent?) : Uri? {
if (resultCode != RESULT_OK) {
return null
return if (resultCode == RESULT_OK) {
intent?.data ?: cameraImageUri // Return the image URI captured by the camera
} else {
null
}

return intent?.data ?: cameraImageUri
}

private fun createImageFile(context: Context): File {
Expand Down
Loading