Skip to content

Commit

Permalink
Fixed a reported IllegalStateException.
Browse files Browse the repository at this point in the history
  • Loading branch information
Guillaume Payet committed Jan 27, 2023
1 parent e5d3f41 commit 44bd267
Showing 1 changed file with 19 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,17 +73,15 @@ interface IBluetoothConnector {
onUserDeclinedBluetooth()
},
onGranted = {
activity.registerPermissionResultCallback(permissionResultCallback)
activity.requestPermission(permission)
requestPermission(permission)
}
).show(activity.supportFragmentManager, null)

activity.isShowingDialog = true
}
}
!userHasDeclinedBluetooth -> {
activity.registerPermissionResultCallback(permissionResultCallback)
activity.requestPermission(permission)
requestPermission(permission)
}
}

Expand All @@ -104,12 +102,28 @@ interface IBluetoothConnector {
!userHasDeclinedBluetooth -> {
if (!activity.isShowingDialog) {
activity.registerActivityResultCallback(activityResultCallback)
activity.startActivityForResult(Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE))

try {
activity.startActivityForResult(Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE))
} catch (e: IllegalStateException) {
activity.unregisterActivityResultCallback(activityResultCallback)
}

activity.isShowingDialog = true
}
}
}

return null
}

private fun requestPermission(permission: String) {
activity.registerPermissionResultCallback(permissionResultCallback)

try {
activity.requestPermission(permission)
} catch (e: IllegalStateException) {
activity.unregisterPermissionResultCallback(permissionResultCallback)
}
}
}

0 comments on commit 44bd267

Please sign in to comment.