Permissionsdispatcher: Make the annotations arguments dynamic

Created on 27 Feb 2020  ·  2Comments  ·  Source: permissions-dispatcher/PermissionsDispatcher

I would like to push the code for the 3 handler methods to a super activity. and I want to pass the permissions required as arguments for the activity during initialization or as a method. is this possible?

I tried to make the args dynamic for @NeedsPermission but got the error -
annotation parameter must be compile-time constant

inquiry

Most helpful comment

Yeah, I thought so. this is library is perfect to be used inside the activity. but I wanted to squeeze those methods inside the parent. please consider adding such functionality where the code does not require to be written on the main presenter page.

regards

All 2 comments

Yeah, this is impossible with a purely annotation-based approach, since those are processed at compilation time and cannot receive dynamic information at runtime - hence why you're getting this particular message from the compiler. The only way to make a non-literal work in an annotation would be a const val in Kotlin, but that's technically not even a variable anyway, and it wouldn't help you at runtime either.

Unfortunately, I'm afraid you'll have to find a different solution for your use case.

Yeah, I thought so. this is library is perfect to be used inside the activity. but I wanted to squeeze those methods inside the parent. please consider adding such functionality where the code does not require to be written on the main presenter page.

regards

Was this page helpful?
0 / 5 - 0 ratings