fixed crash on file upload cancellation
This commit is contained in:
parent
c9a7e93b6a
commit
fc5ce8e992
1 changed files with 27 additions and 19 deletions
|
@ -142,29 +142,37 @@ class MainActivity : Activity() {
|
||||||
return super.onKeyDown(keyCode, event)
|
return super.onKeyDown(keyCode, event)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onActivityResult(requestCode: Int, resultCode: Int, intent: Intent) {
|
override fun onActivityResult(requestCode: Int, resultCode: Int, intent: Intent?) {
|
||||||
if (requestCode != FILECHOOSER_RESULTCODE || filePathCallback == null) return
|
super.onActivityResult(requestCode, resultCode, intent)
|
||||||
if (resultCode != RESULT_OK || intent == null) {
|
try {
|
||||||
filePathCallback!!.onReceiveValue(null)
|
if(resultCode != RESULT_CANCELED) {
|
||||||
} else {
|
if (requestCode != FILECHOOSER_RESULTCODE || filePathCallback == null) return
|
||||||
var uris: Array<Uri?>?
|
if (resultCode != RESULT_OK || intent == null) {
|
||||||
try {
|
filePathCallback!!.onReceiveValue(null)
|
||||||
val clipData = intent.clipData
|
} else {
|
||||||
if (clipData != null) { // multiple items
|
var uris: Array<Uri?>?
|
||||||
uris = arrayOfNulls(clipData.itemCount)
|
try {
|
||||||
for (i in 0 until clipData.itemCount) {
|
val clipData = intent.clipData
|
||||||
uris[i] = clipData.getItemAt(i).uri
|
if (clipData != null) { // multiple items
|
||||||
|
uris = arrayOfNulls(clipData.itemCount)
|
||||||
|
for (i in 0 until clipData.itemCount) {
|
||||||
|
uris[i] = clipData.getItemAt(i).uri
|
||||||
|
}
|
||||||
|
} else { // single item
|
||||||
|
uris = arrayOf(intent.data)
|
||||||
|
}
|
||||||
|
} catch (ex: Exception) {
|
||||||
|
e("Error during file upload", ex)
|
||||||
|
uris = null
|
||||||
}
|
}
|
||||||
} else { // single item
|
filePathCallback!!.onReceiveValue(uris)
|
||||||
uris = arrayOf(intent.data)
|
|
||||||
}
|
}
|
||||||
} catch (ex: Exception) {
|
filePathCallback = null
|
||||||
e("Error during file upload", ex)
|
|
||||||
uris = null
|
|
||||||
}
|
}
|
||||||
filePathCallback!!.onReceiveValue(uris)
|
|
||||||
}
|
}
|
||||||
filePathCallback = null
|
catch (ex: Exception) {
|
||||||
|
// it is well known that the best fix for the crash is to wrap the entire function in a try/catch block
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun explodeAndroid() {
|
private fun explodeAndroid() {
|
||||||
|
|
Loading…
Reference in a new issue