user3068771
user3068771

Reputation: 41

Requesting permission in AAR for Marshmallow

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?

Upvotes: 4

Views: 398

Answers (2)

RexSplode
RexSplode

Reputation: 1505

You can request permissions using fragments as and argument to that method, but it also will end up in either including fragments (and thus the activity) into your AAR, or requesting the fragment as an argument to your method.

Upvotes: 0

CommonsWare
CommonsWare

Reputation: 1006944

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

No.

Upvotes: 1

Related Questions