Module PermissionsAndroid-BsReactNative

type result =
| GRANTED
| DENIED
| NEVER_ASK_AGAIN
;

You can read more on PermissionsAndroid API usage in official docs: https://facebook.github.io/react-native/docs/permissionAndroid

Example of use

Requesting single permission.
let requestPermissions = () =>
  PermissionsAndroid.request(
    ~permission=PermissionsAndroid.Permission.SEND_SMS,
    ~rationale=
      PermissionsAndroid.rationale(
        ~title="Hello!",
        ~message="Cool app wants to send SMS...",
        (),
      ),
    (),
  )
  |> Js.Promise.then_(permissions => {
       Js.log(permissions);
       Js.Promise.resolve();
     })
  |> ignore;
Requesting multiple permissions.
let requestMultiplePermissions = () => {
  PermissionsAndroid.requestMultiple(
    ~permissions=[
      PermissionsAndroid.Permission.SEND_SMS,
      PermissionsAndroid.Permission.READ_EXTERNAL_STORAGE,
      PermissionsAndroid.Permission.WRITE_EXTERNAL_STORAGE,
    ],
  )
  |> Js.Promise.then_(res => {
       Js.log(res);
       Js.Promise.resolve();
     })
  |> ignore;

  ();
};
Functions

check

let check: Permission.t => Js.Promise.t(bool);
request
let request:
  (~permission: Permission.t, ~rationale: rationale=?, unit) =>
  Js.Promise.t(result);

To create rationale paramters use PermissionsAndroid.rationale function.

PermissionsAndroid.rationale(
  ~title="Hello!",
  ~message="Cool app wants to send SMS...",
  (),
),
requestMultiple
let requestMultiple:
  (~permissions: list(Permission.t)) => Js.Promise.t(Js.Dict.t('a));
rationale

To create rationale for showing why you want to get permission.

let requestMultiple: (~title=string=?, ~message=string=?, unit) => rationale; 

Permissions that require prompting the user

All possieble values are avaliable via PermissionsAndroid.Permission

PermissionsAndroid.Permission.READ_CALENDAR;
PermissionsAndroid.Permission.WRITE_CALENDAR;
PermissionsAndroid.Permission.CAMERA;
PermissionsAndroid.Permission.READ_CONTACTS;
PermissionsAndroid.Permission.WRITE_CONTACTS;
PermissionsAndroid.Permission.GET_ACCOUNTS;
PermissionsAndroid.Permission.ACCESS_FINE_LOCATION;
PermissionsAndroid.Permission.ACCESS_COARSE_LOCATION;
PermissionsAndroid.Permission.RECORD_AUDIO;
PermissionsAndroid.Permission.READ_PHONE_STATE;
PermissionsAndroid.Permission.CALL_PHONE;
PermissionsAndroid.Permission.READ_CALL_LOG;
PermissionsAndroid.Permission.WRITE_CALL_LOG;
PermissionsAndroid.Permission.ADD_VOICEMAIL;
PermissionsAndroid.Permission.USE_SIP;
PermissionsAndroid.Permission.PROCESS_OUTGOING_CALLS;
PermissionsAndroid.Permission.BODY_SENSORS;
PermissionsAndroid.Permission.SEND_SMS;
PermissionsAndroid.Permission.RECEIVE_SMS;
PermissionsAndroid.Permission.READ_SMS;
PermissionsAndroid.Permission.RECEIVE_WAP_PUSH;
PermissionsAndroid.Permission.RECEIVE_MMS;
PermissionsAndroid.Permission.READ_EXTERNAL_STORAGE;
PermissionsAndroid.Permission.WRITE_EXTERNAL_STORAGE;
Results for requesting
PermissionsAndroid.GRANTED
PermissionsAndroid.DENIED
PermissionsAndroid.NEVER_ASK_AGAIN
include { ... };
include module type of { ... };
type rationale;
let rationale: ?⁠title:string => ?⁠message:string => unit => rationale;
let title: rationale => option(string);
let titleGet: rationale => option(string);
let message: rationale => option(string);
let messageGet: rationale => option(string);
module Permission: { ... };
let check: Permission.t => Js.Promise.t(bool);
let request: permission:Permission.t => ?⁠rationale:rationale => unit => Js.Promise.t(result);
let requestMultiple: permissions:list(Permission.t) => Js.Promise.t(Js.Dict.t('a));