PermissionsKepler
PermissionsKepler
provides access to the Kepler permissions model.
Example
import * as React from 'react';
import { useState } from 'react';
import {
Button,
Text,
View
} from 'react-native';
import { usePermissionsKepler, PERMISSIONS } from '@amzn/react-native-kepler';
const App = () => {
const [checkStatus, setCheckStatus] = useState('none');
const [requestStatus, setRequestStatus] = useState('none');
const [check, request] = usePermissionsKepler();
const handlePermissionCheck = async (permission) => {
try {
const hasPermission = await check(permission);
setCheckStatus(hasPermission ? "True" : "False");
} catch (error) {
console.error("Error checking permissions:", error);
setCheckStatus(`Error: ${error.message}`);
}
};
const handlePermissionRequest = async (permission) => {
try {
const requestResult = await request(permission);
setRequestStatus(requestResult ? "True" : "False");
} catch (error) {
console.error("Error during permission request:", error);
setRequestStatus(`Error: ${error.message}`);
}
};
return (
<View style={{ flex: 1 }}>
<View style={{ marginVertical: 10 }}>
<Text style={{ color: 'white', fontSize: 24 }}>Check permission</Text>
<Button
onPress={() => handlePermissionCheck(PERMISSIONS.ACCESS_COARSE_LOCATION)}
title={'Check'}
/>
</View>
<Text style={{ textAlign: 'center', color: 'white', fontSize: 20 }}>{checkStatus}</Text>
<View style={{ marginVertical: 10 }}>
<Text style={{ color: 'white', fontSize: 24 }}>Request permission</Text>
<Button
onPress={() => handlePermissionRequest(PERMISSIONS.ACCESS_COARSE_LOCATION)}
title={'Request'}
/>
</View>
<Text style={{ textAlign: 'center', color: 'white', fontSize: 20 }}>{requestStatus}</Text>
</View>
);
};
export default App;
Reference
Hooks
usePermissionsKepler
const [check, request] = usePermissionsKepler();
Returns an array containing two methods to check and request specific permissions.
Methods
check
check(permission: Permission): Promise<boolean>;
Returns a promise that resolves to a boolean value that indicates whether the specified permissions has been granted.
Parameters:
Name | Type | Required | Description |
---|---|---|---|
permission | Permission | Yes | Checks if a specific permission has been granted. |
request
request(permission: Permission): Promise<PermissionStatus>;
Requests the specified user permission.
Parameters:
Name | Type | Required | Description |
---|---|---|---|
permission | Permission | Yes | The function checks whether the permission is already granted. If the permission is already granted, it automatically resolves to granted without showing any dialog. If the permission is not granted, a dialog appears prompting the user with Allow/Deny options. |
Remarks
The process flow depends on the current state of the permission:
- Permission Already Granted:
- The function automatically resolves to
granted
without displaying any dialog if the requested permission has already been granted.
- The function automatically resolves to
- Permission Not Granted:
- If the permission has not been granted, a dialog box is presented to the user with
Allow
andDeny
options. - User Selects
Allow
:- The function resolves to
granted
. - All future requests for this specific permission will automatically resolve to
true
as well, without showing the dialog again.
- The function resolves to
- User Selects
Deny
:- The function resolves to
denied
. - The specific permission request requires that the dialog is shown again on subsequent requests.
- The function resolves to
- If the permission has not been granted, a dialog box is presented to the user with
Returns
Return Type: Promise<PermissionStatus>
One of the PermissionStatus
values.
PERMISSIONS
The following table lists the supported permissions.
Name | Permission | Description |
---|---|---|
NET_INFO | com.amazon.network.privilege.net-info | Allows access to the device IP address and network information. |
ACCESS_ACCESSORY_CONTROL_ACCOUNT | com.amazon.acc.privilege.access | Allows initialization and deinitialization of ACC client, performing accessory list querying and performing accessory info querying. |
CONNECT_ACCESSORY_CONTROL_ACCOUNT | com.amazon.acc.privilege.connect | Allows accessory connect and disconnect. |
DISCOVER_ACCESSORY_CONTROL_ACCOUNT | com.amazon.acc.privilege.discover | Allows accessory discovery. |
ACCESS_COARSE_LOCATION | com.amazon.location.privilege.access.coarse | Allows retreival of the coarse geolocation. |
ACCESS_FINE_LOCATION | com.amazon.location.privilege.access.fine | Allows retreival fine geolocation and listen to periodic geolocation tracking updates. |
RECORD_AUDIO | com.amazon.audio.privilege.microphone.access | Allows access to the device's microphone. |
DEVICE_FRIENDLY_NAME | com.amazon.devconf.privilege.identifiers.device-friendly-name | Allows the caller to read the device friendly name. |
BLUETOOTH_ADVERTISE | com.amazon.bluetooth.privilege.advertise | Required to use BLE advertisement methods. |
BLUETOOTH_DISCOVERABLE | com.amazon.bluetooth.privilege.discoverable | Required to enable Bluetooth connection. |
READ_EXTERNAL_STORAGE | com.amazon.external-disk.privilege.readonly | Allows access to external storage in read-only mode. |
DISCOVERABLE_ACCESSORY_CONTROL_ACCOUNT | com.amazon.acc.privilege.discoverable | Allows setting of the device visibility mode. |
CAMERA | com.amazon.camera.privilege.access | Allows access to the device's camera. |
READ_CALENDAR | com.amazon.calendar.privilege.read | Allows access to read from calendar service. |
WRITE_CALENDAR | com.amazon.calendar.privilege.write | Allows access to write to calendar service . |
PermissionStatus
Name | Description |
---|---|
granted | Permission is granted |
denied | Permission request is rejected, for the subsequent call it will prompt user again |
Last updated: Sep 30, 2025