Requesting permission in AAR for Marshmallow

Viewed 306

I have an Android application and AAR library which is used by the application. For Version <= 22 everything was fine. Now I want my application and library to work with marshmallow. Now to get permission for Locations, my application need to request the permissions with ActivityCompact.requestPermissions.

What I want is to request the permission in the AAR and keep application free from caring about the permissions. So, when I call some library (AAR) method say Xyz() from the application, I want to request permission for ACCESS_COARSE_LOCATION.

private void Xyz(){
    if(Build.VERSION > 22){
     //Request permission.
    }else{

    }
}

Request permission with ActivityCompact.requestPermission required Activity as the first argument. My AAR does not contain any Activity. Also, I cannot ask to pass Activity Context because Application can call Xyz() from non Activity class also.

Is there any way I can request permission in my AAR where there is no Activity available?

2 Answers
Related