Packagecom.myflashlab.air.extensions.nativePermissions
Classpublic class PermissionCheck
InheritancePermissionCheck Inheritance Object

PermissionCheck class lets you check if your app has access to a specific hardware or a native feature that is considered dangerous by the OS. Dangerous permissions are those that may deal with users privacy context.

Prior to Android 6.0, you just needed to ask for permissions in the manifest .xml file but that is changed now and Android is asking for dangerous permissions in runtime, similar to how it has been working on iOS.

iOS: Considering that permissions work a bit different on the iOS side compared to the Android side, You should know the difference in details in order to be able to build your UI. Below is how you should work with permissions on the iOS side:

Android: unlike the iOS side, working with permissions on Android is more dynamic. Here's how it works:

Dangerous permissions on iOS supported by this ANE:

Dangerous permissions on Android supported by this ANE:



Public Methods
 MethodDefined By
  
Do not initialize using the constructor, instead use PermissionCheck.init();.
PermissionCheck
  
check($src:String):int
[static] Call this method to check if your app has access to the specific permission or not.
PermissionCheck
  
init():void
[static] Start using the ANE by calling this method.
PermissionCheck
  
[static] Call this method to open the app's setting menu so the user can see the list of permissions your app is using.
PermissionCheck
  
request($src:String, $resultFunc:Function):void
[static] Call this method to ask the OS to give your app access to a specific permission.
PermissionCheck
  
requestMulti($srcs:Array, $resultFunc:Function):void
[static] You may use this method on Android to ask for permissions all at once in a single popup window.
PermissionCheck
  
shouldShowRequest($src:String):Boolean
[static] Gets whether you should show UI with rationale for requesting a permission.
PermissionCheck
Public Constants
 ConstantDefined By
  EXTENSION_ID : String = com.myflashlab.air.extensions.permissionCheck
[static]
PermissionCheck
  PERMISSION_DENIED : int = 2
[static] This state means that your user has denied the requested permission
PermissionCheck
  PERMISSION_GRANTED : int = 1
[static] This state means that your user has granted the requested permission to your app
PermissionCheck
  PERMISSION_OS_ERR : int = 0
[static] This is returned when you are calling a source on a wrong OS!
PermissionCheck
  PERMISSION_UNKNOWN : int = 3
[static] If you are checking a permission for the first time, this value will be returned.
PermissionCheck
  SOURCE_CALENDAR : String = onCalendarPermissionState
[static] User calendar native access (Android+iOS)
PermissionCheck
  SOURCE_CAMERA : String = onCameraPermissionState
[static] Camera native access (Android+iOS)
PermissionCheck
  SOURCE_CONTACTS : String = onContactsPermissionState
[static] User contacts native access (Android+iOS)
PermissionCheck
  SOURCE_LOCATION : String = onLocationPermissionState
[static] Location native access (Android)
PermissionCheck
  SOURCE_LOCATION_ALWAYS : String = onLocationAlwaysPermissionState
[static] Location always native access (iOS)
PermissionCheck
  SOURCE_LOCATION_WHEN_IN_USE : String = onLocationWhenInUsePermissionState
[static] Location when in use native access (iOS)
PermissionCheck
  SOURCE_MIC : String = onMicPermissionState
[static] Microphone native access (Android+iOS)
PermissionCheck
  SOURCE_PHONE : String = onPhonePermissionState
[static] Phone state native access (Android)
PermissionCheck
  SOURCE_PHOTOS : String = onPhotosPermissionState
[static] Photo gallery native access (iOS)
PermissionCheck
  SOURCE_REMINDER : String = onReminderPermissionState
[static] User reminder native access (iOS)
PermissionCheck
  SOURCE_SENSORS : String = onSensorsPermissionState
[static] Sensors native access (Android)
PermissionCheck
  SOURCE_SMS : String = onSMSPermissionState
[static] SMS native access (Android)
PermissionCheck
  SOURCE_STORAGE : String = onStoragePermissionState
[static] Storage native access (Android)
PermissionCheck
  VERSION : String = 3.1.1
[static]
PermissionCheck
Constructor Detail
PermissionCheck()Constructor
public function PermissionCheck()

Do not initialize using the constructor, instead use PermissionCheck.init();.

Method Detail
check()method
public static function check($src:String):int

Call this method to check if your app has access to the specific permission or not. The returned result on iOS platform is one of the following:

If it's PermissionCheck.PERMISSION_UNKNOWN, you can request for that permission.

Parameters

$src:String

Returns
int
init()method 
public static function init():void

Start using the ANE by calling this method.


Example
The following example will show you how to check and request for a permission.
         import com.myflashlab.air.extensions.nativePermissions.PermissionCheck;
                  PermissionCheck.init();
         var permissionState:int = PermissionCheck.check(PermissionCheck.SOURCE_CAMERA);
                  // If this is the first time you are trying to access a feature, the iOS side will return PERMISSION_UNKNOWN
         // but the Android side returns PERMISSION_DENIED.
         if(permissionState == PermissionCheck.PERMISSION_UNKNOWN || permissionState == PermissionCheck.PERMISSION_DENIED)
         {
             PermissionCheck.request(PermissionCheck.SOURCE_CAMERA, onRequestResult);
         }
                  private function onRequestResult($obj:Object):void
         {
             // $obj.source indicates the permission you have requested
             // $obj.state is either PERMISSION_DENIED or PERMISSION_GRANTED
         }
         
openSettings()method 
public static function openSettings():void

Call this method to open the app's setting menu so the user can see the list of permissions your app is using.

request()method 
public static function request($src:String, $resultFunc:Function):void

Call this method to ask the OS to give your app access to a specific permission. The result will be returned to a function that you will pass as the second parameter.

Parameters

$src:String
 
$resultFunc:Function


Example
When developing, you may need to consume an already owned item. On the Android side, you may do as follow:
         private function onRequestResult($state:int):void
         {
             // $state is either PERMISSION_DENIED or PERMISSION_GRANTED
             trace($state)
         }
         
requestMulti()method 
public static function requestMulti($srcs:Array, $resultFunc:Function):void

You may use this method on Android to ask for permissions all at once in a single popup window.

Parameters

$srcs:Array
 
$resultFunc:Function

shouldShowRequest()method 
public static function shouldShowRequest($src:String):Boolean

Gets whether you should show UI with rationale for requesting a permission. You should do this only if you do not have the permission and the context in which the permission is requested does not clearly communicate to the user what would be the benefit from granting this permission.

Read here for the logic of how you should use this method: https://stackoverflow.com/a/34612503/247658

Parameters

$src:String

Returns
Boolean
Constant Detail
EXTENSION_IDConstant
public static const EXTENSION_ID:String = com.myflashlab.air.extensions.permissionCheck

PERMISSION_DENIEDConstant 
public static const PERMISSION_DENIED:int = 2

This state means that your user has denied the requested permission

PERMISSION_GRANTEDConstant 
public static const PERMISSION_GRANTED:int = 1

This state means that your user has granted the requested permission to your app

PERMISSION_OS_ERRConstant 
public static const PERMISSION_OS_ERR:int = 0

This is returned when you are calling a source on a wrong OS!

PERMISSION_UNKNOWNConstant 
public static const PERMISSION_UNKNOWN:int = 3

If you are checking a permission for the first time, this value will be returned. This is a sign for you to know that you can send a request for that permission

SOURCE_CALENDARConstant 
public static const SOURCE_CALENDAR:String = onCalendarPermissionState

User calendar native access (Android+iOS)

SOURCE_CAMERAConstant 
public static const SOURCE_CAMERA:String = onCameraPermissionState

Camera native access (Android+iOS)

SOURCE_CONTACTSConstant 
public static const SOURCE_CONTACTS:String = onContactsPermissionState

User contacts native access (Android+iOS)

SOURCE_LOCATIONConstant 
public static const SOURCE_LOCATION:String = onLocationPermissionState

Location native access (Android)

SOURCE_LOCATION_ALWAYSConstant 
public static const SOURCE_LOCATION_ALWAYS:String = onLocationAlwaysPermissionState

Location always native access (iOS)

SOURCE_LOCATION_WHEN_IN_USEConstant 
public static const SOURCE_LOCATION_WHEN_IN_USE:String = onLocationWhenInUsePermissionState

Location when in use native access (iOS)

SOURCE_MICConstant 
public static const SOURCE_MIC:String = onMicPermissionState

Microphone native access (Android+iOS)

SOURCE_PHONEConstant 
public static const SOURCE_PHONE:String = onPhonePermissionState

Phone state native access (Android)

SOURCE_PHOTOSConstant 
public static const SOURCE_PHOTOS:String = onPhotosPermissionState

Photo gallery native access (iOS)

SOURCE_REMINDERConstant 
public static const SOURCE_REMINDER:String = onReminderPermissionState

User reminder native access (iOS)

SOURCE_SENSORSConstant 
public static const SOURCE_SENSORS:String = onSensorsPermissionState

Sensors native access (Android)

SOURCE_SMSConstant 
public static const SOURCE_SMS:String = onSMSPermissionState

SMS native access (Android)

SOURCE_STORAGEConstant 
public static const SOURCE_STORAGE:String = onStoragePermissionState

Storage native access (Android)

VERSIONConstant 
public static const VERSION:String = 3.1.1