I want to check run-time permission inside a fragment. For Reference I followed This question. Permission Dialog is shown correctly but when I grant permission this exception occurs
java.lang.RuntimeException: Failure delivering result ResultInfo{who=@android:requestPermissions:, request=499835773, result=-1, data=Intent { act=android.content.pm.action.REQUEST_PERMISSIONS (has extras) }} to activity {com.test.myApp.dev/com.test.myApp.MyActivity}: java.lang.IndexOutOfBoundsException: Index: 499835773, Size: 5
This is my code in Fragment. For this I have used This Answer as reference
private var activityResultLauncher: ActivityResultLauncher<Array<String>>
init{
this.activityResultLauncher = registerForActivityResult(
ActivityResultContracts.RequestMultiplePermissions()) {result ->
var allAreGranted = true
for(b in result.values) {
allAreGranted = allAreGranted && b
}
if(allAreGranted) {
capturePhoto()
}
}
}
// --- ---
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
// ... ... init views / binding... ...
someBtn.setOnClickListener{
val appPerms = arrayOf(
Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.WRITE_EXTERNAL_STORAGE,
Manifest.permission.CAMERA
)
activityResultLauncher.launch(appPerms)
}
}
Can someone tell me what I am doing wrong and how to rectify it.