Android permissions have two layers, and both are required:
- Declaration. The permission is written into the APK’s manifest when you build. Choose it in Advanced Build → Permissions. The permission step scans your HTML and JavaScript, marks the permissions your code needs and can add them with one tap.
- Runtime approval. For “dangerous” permissions (camera, microphone, location, notifications on Android 13+, activity recognition), the person using your app must approve a system dialog.
A runtime request cannot add a missing declaration. If a permission is not in the manifest, Android denies the request immediately without showing a dialog. If your request always returns granted: false without a dialog, check the project’s permission list first.
The bridge methods take full permission names such as android.permission.CAMERA. None of these methods is Pro-gated.
| Method | Returns / event |
|---|---|
hasPermission |
boolean |
requestPermission |
permissionResult |
requestPermissions |
permissionsResult |
requestNotificationPermission |
permissionResult |
shouldShowRequestPermissionRationale |
boolean |
openAppSettings, openNotificationSettings, openExactAlarmSettings |
appSettingsResult |
hasPermission
AndroidAPI.hasPermission(permission) // → true / false
Checks whether the permission is currently granted. Use it before starting a feature, and again when the user returns from the settings screen.
if (AndroidAPI.hasPermission('android.permission.CAMERA')) {
AndroidAPI.setTorch(true);
}
requestPermission
AndroidAPI.requestPermission(permission, callbackId)
Shows the system permission dialog for one permission. Result event: permissionResult {callbackId, permission, granted}. If the permission is already granted, the result arrives without a dialog.
Ask at the moment the user starts the feature, not when the app opens. Explain in your page why you need it.
window.addEventListener('permissionResult', e => {
const r = e.detail;
if (r.callbackId !== 'mic-1') return;
if (r.granted) startRecording();
else showMessage('Microphone access is needed to record a voice note.');
});
AndroidAPI.requestPermission('android.permission.RECORD_AUDIO', 'mic-1');
requestPermissions
AndroidAPI.requestPermissions(permissionsJson, callbackId)
Requests several permissions at once. permissionsJson is a JSON array string of full names. Result event: permissionsResult {callbackId, results}, where results maps each permission to true or false.
window.addEventListener('permissionsResult', e => {
if (e.detail.callbackId !== 'video-call') return;
const r = e.detail.results;
const ok = r['android.permission.CAMERA'] && r['android.permission.RECORD_AUDIO'];
if (ok) startCall(); else showMessage('Camera and microphone are both required.');
});
AndroidAPI.requestPermissions(JSON.stringify([
'android.permission.CAMERA',
'android.permission.RECORD_AUDIO'
]), 'video-call');
requestNotificationPermission
AndroidAPI.requestNotificationPermission(callbackId)
Requests POST_NOTIFICATIONS on Android 13 and later. On older versions, notifications need no runtime approval and the result reports granted: true immediately. Result event: permissionResult. Declare POST_NOTIFICATIONS in the project.
window.addEventListener('permissionResult', e => {
if (e.detail.callbackId === 'notify') reminderToggle.checked = e.detail.granted;
});
reminderToggle.addEventListener('change', () => {
if (reminderToggle.checked) AndroidAPI.requestNotificationPermission('notify');
});
shouldShowRequestPermissionRationale
AndroidAPI.shouldShowRequestPermissionRationale(permission) // → true / false
Returns true when the user has denied the permission before and Android recommends explaining why you need it. Show your explanation, then request again.
false does not prove that the permission is permanently blocked. It is also false before the first request. A common pattern: request first; if the result is denied and this method then returns false, offer a button to openAppSettings().
function onCameraDenied() {
if (AndroidAPI.shouldShowRequestPermissionRationale('android.permission.CAMERA')) {
showMessage('The camera is used only to scan the code. Try again?');
} else {
showSettingsButton(); // the user may have chosen "Don't ask again"
}
}
openAppSettings
AndroidAPI.openAppSettings()
Opens your app’s system settings page, where the user can turn permissions on manually. Result event: appSettingsResult {screen: "app", success, error}. Opening the page grants nothing. Check hasPermission again when the user returns, for example on visibilitychange.
document.addEventListener('visibilitychange', () => {
if (!document.hidden && AndroidAPI.hasPermission('android.permission.CAMERA')) {
hideSettingsButton();
}
});
settingsButton.onclick = () => AndroidAPI.openAppSettings();
openNotificationSettings
AndroidAPI.openNotificationSettings()
Opens the notification settings for your app. Use it when the user blocked notifications and wants to turn them back on. Result event: appSettingsResult.
openExactAlarmSettings
AndroidAPI.openExactAlarmSettings()
Opens the “Alarms & reminders” permission screen (Android 12+; app settings on older versions). Exact alarms are not granted through a normal dialog. Declare SCHEDULE_EXACT_ALARM in the project, then use canScheduleExactAlarms() when the user returns. Result event: appSettingsResult {screen: "exact_alarm", success, error}.
Permission names you can use
| Feature | Full name for the bridge |
|---|---|
| Camera, torch, web camera | android.permission.CAMERA |
| Microphone | android.permission.RECORD_AUDIO |
| Precise location | android.permission.ACCESS_FINE_LOCATION |
| Approximate location | android.permission.ACCESS_COARSE_LOCATION |
| Notifications (Android 13+) | android.permission.POST_NOTIFICATIONS |
| Step counter | android.permission.ACTIVITY_RECOGNITION |
Permissions without a runtime dialog (INTERNET, ACCESS_NETWORK_STATE, VIBRATE) only need to be declared. Do not request broad storage or all-files access: the file methods in this bridge work without them.