Skip to content

Permissions

Camera, microphone, photos, location, contacts, and notifications are protected by the operating system. Using them takes two steps:

  1. Declare the capability at build time, so the platform knows your app may ask for it (Android manifest permissions, iOS purpose strings).
  2. Request it at runtime, at the moment the user starts the feature that needs it.

PAM Native keeps both steps explicit. Your app ships only the permissions you declare, pam mobile audit lists every one of them before release, and the runtime API uses typed enums instead of platform strings.

Most permissions arrive with the plugin that needs them: installing pushinbr/pam-native-location adds the location permissions, pushinbr/pam-native-notifications adds POST_NOTIFICATIONS, and so on. List any other optional permission your own code needs in pam-native.json:

pam-native.json
{
"android": {
"permissions": [
"android.permission.VIBRATE",
"android.permission.WAKE_LOCK"
]
}
}

When PAM generates the Android project it keeps INTERNET and ACCESS_NETWORK_STATE, adds the permissions you listed plus those declared by installed plugins, and removes every other optional permission from the manifest. A permission nobody declared is simply not in the APK, and the runtime request fails.

Feature Permission(s) Declared by
Location ACCESS_FINE_LOCATION, ACCESS_COARSE_LOCATION pam-native-location
Notifications (Android 13+) POST_NOTIFICATIONS pam-native-notifications
Contacts READ_CONTACTS pam-native-contacts
Voice recording RECORD_AUDIO pam-native-audio
Camera capture, gallery CAMERA, RECORD_AUDIO, READ_MEDIA_IMAGES, READ_MEDIA_VIDEO, READ_MEDIA_VISUAL_USER_SELECTED, READ_EXTERNAL_STORAGE pam-native-media
Vibration (Vibration::vibrate()) VIBRATE your pam-native.json
Finite background work WAKE_LOCK your pam-native.json

All names are prefixed with android.permission..

Use Pam\Native\System\Permissions with a PermissionKind. Both calls are asynchronous, return a PermissionDecision, and accept an optional failure closure as their third argument.

src/Receipts/ReceiptCamera.php
<?php
declare(strict_types=1);
namespace App\Receipts;
use Closure;
use Pam\Native\PermissionDecision;
use Pam\Native\PermissionKind;
use Pam\Native\System\Permissions;
final class ReceiptCamera
{
/**
* @param Closure(): void $granted
* @param Closure(PermissionDecision): void $notGranted
*/
public static function ensureAccess(Closure $granted, Closure $notGranted): void
{
Permissions::status(PermissionKind::Camera, static function (PermissionDecision $decision) use ($granted, $notGranted): void {
if ($decision->granted()) {
$granted();
return;
}
if (!$decision->canAskAgain) {
$notGranted($decision); // Blocked: only Settings can change it.
return;
}
Permissions::requestKind(PermissionKind::Camera, static function (PermissionDecision $result) use ($granted, $notGranted): void {
$result->granted() ? $granted() : $notGranted($result);
});
});
}
}
Property / method Meaning
$decision->kind The PermissionKind you asked about
$decision->status PermissionStatus::Granted, Denied, Blocked, Limited, or Unavailable
$decision->canAskAgain true when a new system prompt can still appear
$decision->granted() true for Granted and Limited
$decision->unavailable() true when the permission does not exist on this platform or OS version

Limited is a real, usable grant:

  • Photos — the user shared only selected photos (Android 14+, iOS). Your gallery query returns just those items.
  • Location — on Android the user granted approximate (coarse) location only.
PermissionKind Value
Camera 1
Microphone 2
Photos 3
Notifications 4
LocationWhenInUse 5
Contacts 6
BluetoothConnect 7
FullScreenIntent 8
PhoneState 9

Plugins that need other protected resources (Bluetooth, health data, NFC) expose their own authorization calls; see the plugin catalog.

The system prompt appears once or twice in an app’s lifetime. Make it count:

  • Ask at the point of use. Request the camera when the user taps “Scan receipt”, not on the first launch.
  • Explain first when the reason is not obvious. Show your own short explanation with a clear action, then trigger the system prompt from that action.
  • Degrade gracefully. A denied permission should leave the rest of the app working, with a fallback such as the system file picker.
src/Screens/LocationRationale.php
<?php
declare(strict_types=1);
namespace App\Screens;
use Pam\Native\Attributes\State;
use Pam\Native\Component;
use Pam\Native\Element;
use Pam\Native\PermissionDecision;
use Pam\Native\PermissionKind;
use Pam\Native\PermissionStatus;
use Pam\Native\Style;
use Pam\Native\System\Permissions;
use Pam\Native\UI\Button;
use Pam\Native\UI\Column;
use Pam\Native\UI\SafeAreaView;
use Pam\Native\UI\Screen;
use Pam\Native\UI\Text;
final class LocationRationale extends Component
{
#[State]
public bool $blocked = false;
public function render(): Element
{
return Screen::make(
SafeAreaView::make(
Column::make(
Text::make('Find stores near you')->style(new Style(fontSize: 24, fontWeight: 700)),
Text::make('We use your location only while this screen is open to sort stores by distance.'),
$this->blocked
? Button::make('Open Settings')->onPress($this->openSettings(...))
: Button::make('Continue')->onPress($this->request(...)),
)->style(new Style(flexGrow: 1, padding: 24, gap: 16)),
)->style(new Style(flexGrow: 1)),
)->style(new Style(flexGrow: 1));
}
public function request(): void
{
Permissions::requestKind(PermissionKind::LocationWhenInUse, function (PermissionDecision $decision): void {
$this->blocked = $decision->status === PermissionStatus::Blocked;
// On success, navigate to the store list.
});
}
public function openSettings(): void
{
Permissions::openSettings();
}
}

Android sometimes asks apps to explain a permission before prompting again (after the user declined once). Pass a PermissionRationale and PAM shows it in a native alert only when Android says a rationale is due; iOS never asks for one:

use Pam\Native\PermissionKind;
use Pam\Native\PermissionRationale;
use Pam\Native\System\Permissions;
Permissions::requestKind(
PermissionKind::Camera,
fn ($decision) => $decision->granted() ? $this->openScanner() : null,
rationale: new PermissionRationale(
title: 'Camera access',
message: 'The camera is used only to scan receipts.',
confirmLabel: 'Continue',
cancelLabel: 'Not now',
),
);

Permissions::shouldShowRationale($kind, $callback) exposes the same signal if you prefer your own UI.

When canAskAgain is false (status Blocked), the operating system will not show the prompt again. Explain what the feature needs and offer Permissions::openSettings(), which opens your app’s page in system settings. Re-check the status in resumed() when the user comes back:

public function resumed(): void
{
Permissions::status(PermissionKind::LocationWhenInUse, function (PermissionDecision $decision): void {
$this->blocked = !$decision->granted() && !$decision->canAskAgain;
});
}

Only open Settings in response to a user action — never automatically.

Permissions::check(string $permission, $callback) and Permissions::request(string $permission, $callback) accept a raw platform permission name and report a plain bool. Prefer status() and requestKind(): they distinguish denied from blocked and limited access and behave the same on both platforms.

pam mobile audit lists every native authority your app aggregates — Android permissions, deep links, share targets, Maven repositories and dependencies, iOS purpose strings and entitlements — from your manifest and every installed plugin, sorted by severity.

Terminal window
pam mobile audit
pam mobile audit --deny-high
pam mobile audit --json > artifacts/mobile-release-audit.json
Severity Examples
Critical MANAGE_EXTERNAL_STORAGE, REQUEST_INSTALL_PACKAGES, QUERY_ALL_PACKAGES, SYSTEM_ALERT_WINDOW, NSUserTrackingUsageDescription, unpinned Maven dependencies
High Location, contacts, camera, microphone, media, calendar, SMS, health, Bluetooth, NFC, Face ID; plugin entitlements
Info INTERNET, ACCESS_NETWORK_STATE

--deny-high makes the command fail when any high or critical finding exists, which is a good gate for CI on apps that should not touch sensitive data. Keep each sensitive permission only while a shipped feature needs it.