Karumi / Dexter

Android library that simplifies the process of requesting permissions at runtime.
http://karumi.com
Apache License 2.0
5.23k stars 671 forks source link

check permission on Application context, without Activity #167

Closed RuiMiguel closed 4 years ago

RuiMiguel commented 7 years ago

Expected behaviour

Provide public API on Dexterobject to init with Application Context, not just with Activity to check permissions with no Activity (launching DexterActivity to do it)

Actual behaviour

I've seen that on DexterInstanceTest Application Context is used to setup it and check permissions test run ok. When calls DexterInstanceTest->startTransparentActivityIfNeeded checks if context is instanceof Application. But DexterInstance is not a public class so, couldn't use it outside library

Steps to reproduce

run tests on DexterInstanceTest, setup mock Context with Application

Version of the library

4.1.1

Serchinastico commented 7 years ago

Hi @RuiMiguel,

Thanks for reporting! I know there was a reason we were asking for an Activity instead of the Application context before but, reviewing the code as it is right now, I don't see why we couldn't ask for a Context instead. In the end, we are only using it in PermissionChecker.checkSelfPermission(context, permission) and the ghost activity we create when we really need to ask the user for permissions.

I feel reluctant to accept Context instances again (I remember some issues with the activity stack) but we can review a PR if you feel like implementing it yourself.