From 118333cb43d3effbf93c751ccf19ee18d2f904c8 Mon Sep 17 00:00:00 2001 From: Subbramanian Lakshmanan Date: Fri, 31 May 2019 13:39:17 -0500 Subject: [PATCH] fix: Fixes issue to launch file chooser every time - Handles the result code & completes file chooser callback with null return value, when the user cancels the action by clicking back or elsewhere --- .../dev_android/view/main/view/MainActivity.kt | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/to/dev/dev_android/view/main/view/MainActivity.kt b/app/src/main/java/to/dev/dev_android/view/main/view/MainActivity.kt index 10e14a7..b372776 100644 --- a/app/src/main/java/to/dev/dev_android/view/main/view/MainActivity.kt +++ b/app/src/main/java/to/dev/dev_android/view/main/view/MainActivity.kt @@ -77,15 +77,19 @@ class MainActivity : BaseActivity(), CustomWebChromeClient. } override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { + if (requestCode != PIC_CHOOSER_REQUEST) { + return super.onActivityResult(requestCode, resultCode, data) + } + if (resultCode == Activity.RESULT_OK) { - if (requestCode == PIC_CHOOSER_REQUEST) { - if (data != null) { - mFilePathCallback?.onReceiveValue(arrayOf(data.data)) - mFilePathCallback = null - } + if (data != null) { + mFilePathCallback?.onReceiveValue(arrayOf(data.data)) + mFilePathCallback = null } + } else if (resultCode == Activity.RESULT_CANCELED) { + mFilePathCallback?.onReceiveValue(null) + mFilePathCallback = null } - super.onActivityResult(requestCode, resultCode, data) } companion object {