canelmas / let

Annotation based simple API flavored with AOP to handle new Android runtime permission model
Apache License 2.0
530 stars 40 forks source link

Method call is not forwarded after granting permission #9

Closed renaudcerrato closed 8 years ago

renaudcerrato commented 8 years ago

Running 6.0.1 on a Nexus 6, I noticed that my methods were not called right after granting permissions. After a few debug, I can clearly see that the request code given to onRequestPermissionsResult() has an offset of 256 compared to the task number in DelayedTasks - resulting in a "No delayed task to execute.

It looks like requestPermissions() is adding 256 to the given request code (or ORing it with 0x100 since only first 8 bits can be used as request code).

As a quick and dirty fix, I had to write the following to make it works:

@Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
        Let.handle(this, requestCode & 0xff, permissions, grantResults);
    }
renaudcerrato commented 8 years ago

Ok, forget about it: I was catching the onRequestPermissionResult() in the Activity while the permission has been requested from a fragment. The framework is effectively ORing request codes coming from fragments with 0x100 for safety.