Is it possible to register multiple registerForAct...
# android
a
Is it possible to register multiple registerForActivityResult callbacks in a fragment? or is it possible to distinguish between multiple requested permissions?
b
If you use the
RequestMultiplePermissions
contract you’ll get a
Map<String,Boolean>
rather than a
Boolean
in the result that you can then check all of the permissions to see which were granted and which were not.
👍 2
i
And yes, you can call
registerForActivityResult()
multiple times with different callback logic for each
b
That too.
i
That is quite handy with the
registerForActivityResult()
Kotlin extension that lets you define the input at register time (so you tie the input with the callback together): https://developer.android.com/reference/kotlin/androidx/activity/result/package-summary?hl=en#registerforactivityresult_1
which let's you write code like:
Copy code
val requestCameraPermissionLauncher = registerForActivityResult(
  RequestPermission(),
  Manifest.permission.CAMERA
) { isGranted: Boolean ->
}

// now you can just requestCameraPermissionLauncher.launch()
// without any permission here
b
Now if we could get the versions with the activity result in androidx.appcompat out of alpha.
i
The Activity Result APIs themselves are in RC and that's what AppCompat 1.3.0-beta01 uses. Nothing should be alpha anymore at any level
🙌 1
(and you can use AppCompat 1.2.0 with Fragment 1.3.0-rc02+Activity 1.2.0-rc01)
b
Well, that’s excellent news.
a
Ok thanks @Ian Lake @Brian Dupuis! Registering multiple callbacks was what i tried first but i couldn’t get the second one working, will try again today maybe some other problem