Skip to content

Commit 28c2f6d

Browse files
authored
Update FileChooserResultContract.kt (#130)
1 parent 889164a commit 28c2f6d

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

samples/MobileBuyIntegration/app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ android {
3131
applicationId "com.shopify.checkout_sdk_mobile_buy_integration_sample"
3232
minSdk 23
3333
targetSdk 34
34-
versionCode 33
34+
versionCode 34
3535
versionName "0.0.${versionCode}"
3636

3737
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

samples/MobileBuyIntegration/app/src/main/java/com/shopify/checkout_sdk_mobile_buy_integration_sample/FileChooserResultContract.kt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ class FileChooserResultContract : ActivityResultContract<FileChooserParams, Uri?
5656
cameraImageUri = FileProvider.getUriForFile(context, "${context.packageName}.provider", photoFile)
5757
val cameraIntent = Intent(MediaStore.ACTION_IMAGE_CAPTURE).apply {
5858
putExtra(MediaStore.EXTRA_OUTPUT, cameraImageUri)
59+
addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION) // Ensures URI can be written
5960
}
6061

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

6667
override fun parseResult(resultCode: Int, intent: Intent?) : Uri? {
67-
if (resultCode != RESULT_OK) {
68-
return null
68+
return if (resultCode == RESULT_OK) {
69+
intent?.data ?: cameraImageUri // Return the image URI captured by the camera
70+
} else {
71+
null
6972
}
70-
71-
return intent?.data ?: cameraImageUri
7273
}
7374

7475
private fun createImageFile(context: Context): File {

0 commit comments

Comments
 (0)