Requesting Access

When you are going to be accessing a 'dangerous' permission you must check that your application has been allowed access.

On Android these permissions are listed through the manifest additions. On older versions of Android these permissions are accepted when the user installs the application. More modern versions (Marshmallow 6 [v23]+) require that you request the permissions similar to iOS. You will still need to list them in your manifest and then follow the same code below.

You should respect the SHOULD_EXPLAIN status by displaying additional information to your user about why you require this functionality.

switch (Permissions.service.authorisationStatus())
{
case AuthorisationStatus.AUTHORISED:
// This device has been authorised.
break;
case AuthorisationStatus.NOT_DETERMINED:
case AuthorisationStatus.SHOULD_EXPLAIN:
// You are yet to ask for authorisation
// At this point you should consider your strategy to get your
// user to authorise by explaining your need for the permissions
Permissions.service.addEventListener( AuthorisationEvent.CHANGED, authorisationChangedHandler );
Permissions.service.requestAuthorisation();
break;
case AuthorisationStatus.DENIED:
case AuthorisationStatus.UNKNOWN:
case AuthorisationStatus.RESTRICTED:
// The user has disabled the permissions
// Advise your user of the lack of permissions as you see fit
break;
}

You will then receive a change event if the user accepted your permission request:

private function authorisationChangedHandler( event:AuthorisationEvent ):void
{
// Check the authorisation state again (as above)
}