googlesamples / easypermissions

Simplify Android M system permissions
https://firebaseopensource.com/projects/googlesamples/easypermissions/
Apache License 2.0
9.87k stars 1.46k forks source link

MainFragment RC_SMS_PERM requestCode are diffrent in Activity and Fragment #249

Closed jhamin0511 closed 6 years ago

jhamin0511 commented 6 years ago

Basic Information

Device type: ____ OS version: ____ EasyPermissions version: v1.3.0

Describe the problem

Why diffrent requestCode of onPermissionsDenied() in Activity and Fragment?

MainFragment reqestCode[RC_SMS_PERM] is 122, and reqestCode of onPermissionDenied() in fragment interface method is 122.

but, Activity requestCode is 65658.

who is know this diffent?

samtstern commented 6 years ago

@jhamin0511 that's an artifact of how the Android framework forwards activity results to Fragments. Each fragment has an ID and when a result should be targeted at a specific fragment the request code is bit-smashed (I forget the algorithm) with the fragment ID so the Activity knows where to pass it.

Some explanation here: https://stackoverflow.com/a/37836707