/** * Prompts the user to enable a permission and returns a promise resolving to a * boolean value indicating whether the user allowed or denied the request * * If the optional rationale argument is included (which is an object with a * `title` and `message`), this function checks with the OS whether it is * necessary to show a dialog explaining why the permission is needed * (https://developer.android.com/training/permissions/requesting.html#explain) * and then shows the system permission dialog */ async requestPermission(permission: string, rationale?: Rationale) : Promise<boolean> { if (rationale) { const shouldShowRationale = await Permissions.shouldShowRequestPermissionRationale(permission); if (shouldShowRationale) { return new Promise((resolve, reject) => { DialogManagerAndroid.showAlert( rationale, () => reject(new Error('Error showing rationale')), () => resolve(Permissions.requestPermission(permission)) ); }); } } return Permissions.requestPermission(permission); }
/** * Prompts the user to enable multiple permissions in the same dialog and * returns an object with the permissions as keys and strings as values * indicating whether the user allowed or denied the request * * See https://facebook.github.io/react-native/docs/permissionsandroid.html#requestmultiple */ requestMultiple( permissions: Array<string>, ): Promise<{[permission: string]: PermissionStatus}> { return NativeModules.PermissionsAndroid.requestMultiplePermissions( permissions, ); }
/** * Prompts the user to enable a permission and returns a promise resolving to a * string value indicating whether the user allowed or denied the request * * See https://facebook.github.io/react-native/docs/permissionsandroid.html#request */ async request(permission: string, rationale?: Rationale) : Promise<PermissionStatus> { if (rationale) { const shouldShowRationale = await NativeModules.PermissionsAndroid.shouldShowRequestPermissionRationale(permission); if (shouldShowRationale) { return new Promise((resolve, reject) => { NativeModules.DialogManagerAndroid.showAlert( rationale, () => reject(new Error('Error showing rationale')), () => resolve(NativeModules.PermissionsAndroid.requestPermission(permission)) ); }); } } return NativeModules.PermissionsAndroid.requestPermission(permission); }
}babelHelpers.createClass(PermissionsAndroid,[{key:'checkPermission',value:function checkPermission( permission){ return Permissions.checkPermission(permission); }},{key:'requestPermission',value:function requestPermission(
return regeneratorRuntime.async(function request$(_context2) { while (1) { switch (_context2.prev = _context2.next) { case 0: if (!rationale) { _context2.next = 6; break; } _context2.next = 3; return regeneratorRuntime.awrap(Permissions.shouldShowRequestPermissionRationale(permission)); case 3: shouldShowRationale = _context2.sent; if (!shouldShowRationale) { _context2.next = 6; break; } return _context2.abrupt('return', new Promise(function (resolve, reject) { DialogManagerAndroid.showAlert(rationale, function () { return reject(new Error('Error showing rationale')); }, function () { return resolve(Permissions.requestPermission(permission)); }); })); case 6: return _context2.abrupt('return', Permissions.requestPermission(permission)); case 7: case 'end': return _context2.stop(); } } }, null, this);
function(){return resolve(Permissions.requestPermission(permission));});
value: function check(permission) { return Permissions.checkPermission(permission); }
value: function checkPermission(permission) { console.warn('"PermissionsAndroid.checkPermission" is deprecated. Use "PermissionsAndroid.check" instead'); return Permissions.checkPermission(permission); }
value: function requestMultiple(permissions) { return Permissions.requestMultiplePermissions(permissions); }
() => resolve(Permissions.requestPermission(permission))
/** * Returns a promise resolving to a boolean value as to whether the specified * permissions has been granted */ checkPermission(permission: string) : Promise<boolean> { return Permissions.checkPermission(permission); }
/** * Prompts the user to enable multiple permissions in the same dialog and * returns an object with the permissions as keys and strings as values * indicating whether the user allowed or denied the request */ requestMultiple(permissions: Array<string>) : Promise<{[permission: string]: PermissionStatus}> { return Permissions.requestMultiplePermissions(permissions); }
/** * DEPRECATED - use check * * Returns a promise resolving to a boolean value as to whether the specified * permissions has been granted * * @deprecated */ checkPermission(permission: string) : Promise<boolean> { console.warn('"PermissionsAndroid.checkPermission" is deprecated. Use "PermissionsAndroid.check" instead'); return Permissions.checkPermission(permission); }
/** * Returns a promise resolving to a boolean value as to whether the specified * permissions has been granted * * See https://facebook.github.io/react-native/docs/permissionsandroid.html#check */ check(permission: string): Promise<boolean> { return NativeModules.PermissionsAndroid.checkPermission(permission); }
() => resolve( NativeModules.PermissionsAndroid.requestPermission(permission), ),