Mobile development · Intermediate · 22 min
Ask for camera and photo permissions in an Expo app the right way
By Padding · Updated 18 Nov 2026
Expo SDK 58 · expo-camera 58.0.14 · expo-image-picker 58.0.10 · Node.js 26 (node:26)
You will have an Expo screen that explains why it needs the camera before asking, handles every answer including a permanent refusal, offers the photo library as a fallback, and ships only the permissions it uses.
On this page
A permission prompt is a question the operating system asks on your behalf, and you usually get one chance at it. On iOS the camera prompt appears once: after "Don't Allow", only the Settings app can change the answer. On Android 11 and later, a second "Deny" counts as "don't ask again", and your request then fails silently. An app that asks on first launch, with no context, burns that chance on the moment people are least likely to say yes.
In this tutorial you build one screen for a clinic app: "Add a photo of your referral letter". It explains what the photo is for before any system prompt appears, asks for the camera with useCameraPermissions from expo-camera, and handles all four answers the system can give you (plus a brief checking state while it loads). When the camera is refused, the patient can still choose an existing photo through the system photo picker, which needs no permission at all. You also set the text the iOS prompt shows, and remove the microphone and storage permissions the libraries would otherwise add to your Android app.
The permission logic sits in one small function, and the screen is tested with Jest and React Native Testing Library with the native modules mocked, so you can prove each branch without a phone. You see the real dialogs on a phone in the last step.
Step 1 · Create the project and add the camera libraries
Create a new app from the SDK 58 default template in a throwaway folder:
cd ~
npx create-expo-app@5.0.0 referral-photo-demo
cd ~/referral-photo-demoInstall expo-camera for the live camera and expo-image-picker for the photo library. npx expo install chooses the versions that match the SDK:
npx expo install expo-camera expo-image-pickerAdd Jest, the jest-expo preset and React Native Testing Library for the tests later on:
npx expo install jest-expo jest -- --save-dev
npm install --save-dev @testing-library/react-native@14.1.0 test-renderer@1.3.1 @react-native/jest-preset@0.88.1 @types/jest@30.0.0
npm pkg set jest.preset=jest-expoCheck it worked
Print the two library versions:
node -p 'const d = require("./package.json").dependencies; [d["expo-camera"], d["expo-image-picker"]].join(" ")'You see ~58.0.14 ~58.0.10, or later 58.0 patches. A different major version means the project is not on SDK 58; check expo in package.json.
Step 2 · Write the prompt text and drop the permissions you do not use
Both libraries ship config plugins. When Expo generates the native projects, the plugins write the iOS usage description strings into Info.plist and the Android permissions into AndroidManifest.xml. Left at their defaults, they write generic text such as "Allow $(PRODUCT_NAME) to access your camera", and both of them add microphone access for video recording, which a photo screen never uses.
iOS shows your usage string inside the system prompt, so it is the only text the patient reads at the moment of decision. Say what the camera is for in plain words. Apple rejects apps whose strings are vague or missing.
On Android there is a second source of permissions. expo-image-picker's own manifest asks for READ_EXTERNAL_STORAGE and WRITE_EXTERNAL_STORAGE on Android 12 and older. This screen does not need them: the system photo picker hands your app the one photo the patient chose. The only way to remove a permission that a library's manifest adds is android.blockedPermissions. Blocking READ_MEDIA_IMAGES and READ_MEDIA_VIDEO as well stops any future library from adding them; Google Play only allows those two when the system picker cannot do the job.
This Node script updates app.json the same way whatever else it holds, and replaces any earlier entries for the two plugins:
node -e '
const fs = require("fs")
const app = JSON.parse(fs.readFileSync("app.json", "utf8"))
const cameraText = "Take a photo of your referral letter so the clinic can read it before your visit."
const ours = ["expo-camera", "expo-image-picker"]
const others = (app.expo.plugins ?? []).filter((p) => !ours.includes(Array.isArray(p) ? p[0] : p))
app.expo.plugins = [
...others,
["expo-camera", { cameraPermission: cameraText, microphonePermission: false, recordAudioAndroid: false }],
[
"expo-image-picker",
{
photosPermission: "Choose a photo of your referral letter that is already on this phone.",
cameraPermission: cameraText,
microphonePermission: false,
},
],
]
app.expo.android = {
...app.expo.android,
blockedPermissions: [
"android.permission.RECORD_AUDIO",
"android.permission.READ_EXTERNAL_STORAGE",
"android.permission.WRITE_EXTERNAL_STORAGE",
"android.permission.READ_MEDIA_IMAGES",
"android.permission.READ_MEDIA_VIDEO",
],
}
fs.writeFileSync("app.json", JSON.stringify(app, null, 2) + "\n")
'microphonePermission: false removes NSMicrophoneUsageDescription from Info.plist instead of writing a default. recordAudioAndroid: false stops expo-camera adding RECORD_AUDIO. The camera string is set in both plugins so neither overwrites the other with generic text. These settings take effect in the next native build, not in a running app or in Expo Go.
Check it worked
npx expo config --type introspect runs the config plugins without writing any native files and prints the result. Save it and pull out the camera, photo and microphone strings and the Android permission entries:
npx expo config --type introspect --json > /tmp/referral-introspect.json
node -e '
const c = JSON.parse(require("fs").readFileSync("/tmp/referral-introspect.json", "utf8"))
const plist = c._internal.modResults.ios.infoPlist
console.log("NSCameraUsageDescription:", plist.NSCameraUsageDescription)
console.log("NSPhotoLibraryUsageDescription:", plist.NSPhotoLibraryUsageDescription)
console.log("NSMicrophoneUsageDescription:", plist.NSMicrophoneUsageDescription ?? "(not set)")
const manifest = c._internal.modResults.android.manifest.manifest
for (const p of manifest["uses-permission"] ?? []) {
console.log(p.$["android:name"], p.$["tools:node"] === "remove" ? "(removed)" : "")
}
'You see your two sentences for the camera and the photo library, NSMicrophoneUsageDescription: (not set), android.permission.CAMERA without a marker, and the five blocked permissions each marked (removed). The template's own entries, such as android.permission.INTERNET and android.permission.VIBRATE, appear too, without a marker. If the camera line still reads "Allow $(PRODUCT_NAME) to access your camera", the plugin entry is missing or misspelt in app.json.
Step 3 · Turn the permission answer into a screen state
useCameraPermissions returns a permission response with three fields that matter: granted, status (undetermined, granted or denied) and canAskAgain. The screen needs one of five states, and the mapping is easy to get subtly wrong, so it lives in a plain function you can test on its own:
- Not loaded yet (
null):checking. The patient sees a short "Checking camera access" line. granted: true:ready. An "Open camera" button.undetermined:explain. Why the app wants the camera, then "Use camera".deniedwithcanAskAgain: true:ask-again. A gentler reminder and "Try again".deniedwithcanAskAgain: false:blocked. How to turn it on, and "Open settings".
The last case is the one most apps miss. When canAskAgain is false, calling the request function returns "denied" straight away and no dialog appears, so a "Try again" button would look broken. The only way forward is the Settings app.
Create src/referral/camera-step.ts:
mkdir -p src/referral/__tests__
cat > src/referral/camera-step.ts <<'TS'
export type CameraPermission = {
granted: boolean
status: 'undetermined' | 'granted' | 'denied'
canAskAgain: boolean
}
export type CameraStep = 'checking' | 'explain' | 'ready' | 'ask-again' | 'blocked'
export function cameraStepFor(permission: CameraPermission | null): CameraStep {
if (!permission) return 'checking'
if (permission.granted) return 'ready'
if (!permission.canAskAgain) return 'blocked'
return permission.status === 'denied' ? 'ask-again' : 'explain'
}
TS
cat > src/referral/__tests__/camera-step.test.ts <<'TS'
import { cameraStepFor } from '../camera-step'
test('waits while the permission is still loading', () => {
expect(cameraStepFor(null)).toBe('checking')
})
test('explains first when the patient has never been asked', () => {
expect(cameraStepFor({ granted: false, status: 'undetermined', canAskAgain: true })).toBe('explain')
})
test('is ready once access is granted', () => {
expect(cameraStepFor({ granted: true, status: 'granted', canAskAgain: true })).toBe('ready')
})
test('offers another try after one refusal', () => {
expect(cameraStepFor({ granted: false, status: 'denied', canAskAgain: true })).toBe('ask-again')
})
test('sends the patient to Settings when the system will not ask again', () => {
expect(cameraStepFor({ granted: false, status: 'denied', canAskAgain: false })).toBe('blocked')
})
TSCheck it worked
npx jest src/referral/__tests__/camera-step.test.ts --ciJest reports Tests: 5 passed, 5 total.
Step 4 · Build the referral photo screen
The screen always opens with the explanation card, whatever the permission state, so the patient knows what the photo is for before any system dialog. The primary button changes with the state from the previous step. The secondary button, "Choose from your photos", is always there: it is the fallback for a refused camera, and the quicker path for anyone who photographed the letter earlier.
Three details are worth knowing before you read the code:
launchImageLibraryAsyncopens the system photo picker. It needs no permission request: the patient picks one photo and the system gives your app only that file. On Android devices without the photo picker, the system file chooser opens instead, again with no permission.- When the patient comes back from the Settings app, the hook does not know anything has changed. The
AppStatelistener re-reads the permission each time the app becomes active, so the screen moves fromblockedtoreadywithout a restart. quality: 0.6keeps the JPEG small. A phone camera photo can be several megabytes; a referral letter stays readable at a fraction of that, which matters to patients paying for prepaid data by the megabyte and to low-end Android phones with little free storage.
Create src/referral/ReferralPhoto.tsx:
cat > src/referral/ReferralPhoto.tsx <<'TSX'
import { CameraView, useCameraPermissions } from 'expo-camera'
import * as ImagePicker from 'expo-image-picker'
import { useEffect, useRef, useState } from 'react'
import { AppState, Image, Linking, Pressable, StyleSheet, Text, View } from 'react-native'
import { cameraStepFor, type CameraPermission } from './camera-step'
const MESSAGES = {
checking: 'Checking camera access…',
explain: 'Your phone will ask if this app can use the camera. We only use it on this screen, to photograph the letter.',
ready: 'Hold the letter flat, in good light, with all four corners showing.',
'ask-again': 'Camera access is off. You can allow it now, or choose a photo you already have.',
blocked: 'Camera access is turned off for this app. Turn it on in Settings, or choose a photo you already have.',
} as const
export function ReferralPhoto() {
const [permission, requestPermission, getPermission] = useCameraPermissions()
const [cameraOpen, setCameraOpen] = useState(false)
const [photoUri, setPhotoUri] = useState<string | null>(null)
const camera = useRef<CameraView>(null)
const step = cameraStepFor(permission as CameraPermission | null)
useEffect(() => {
const subscription = AppState.addEventListener('change', (state) => {
if (state === 'active') getPermission()
})
return () => subscription.remove()
}, [getPermission])
async function onCameraButton() {
if (step === 'blocked') {
await Linking.openSettings()
return
}
const answer = step === 'ready' ? permission : await requestPermission()
if (answer?.granted) setCameraOpen(true)
}
async function takePhoto() {
const photo = await camera.current?.takePictureAsync({ quality: 0.6 })
if (photo) {
setPhotoUri(photo.uri)
setCameraOpen(false)
}
}
async function chooseFromPhotos() {
const result = await ImagePicker.launchImageLibraryAsync({ mediaTypes: ['images'], quality: 0.6 })
if (!result.canceled) setPhotoUri(result.assets[0].uri)
}
if (cameraOpen && step === 'ready') {
return (
<View style={styles.screen}>
<CameraView ref={camera} style={styles.camera} facing="back" />
<Pressable accessibilityRole="button" style={styles.primary} onPress={takePhoto}>
<Text style={styles.primaryText}>Take photo</Text>
</Pressable>
<Pressable accessibilityRole="button" style={styles.secondary} onPress={() => setCameraOpen(false)}>
<Text style={styles.secondaryText}>Cancel</Text>
</Pressable>
</View>
)
}
const primaryLabel = { checking: null, explain: 'Use camera', ready: 'Open camera', 'ask-again': 'Try again', blocked: 'Open settings' }[step]
return (
<View style={styles.screen}>
<Text accessibilityRole="header" style={styles.title}>
Add a photo of your referral letter
</Text>
<Text style={styles.text}>The clinic reads your letter before the visit, so the doctor has it on the day.</Text>
<Text style={styles.text}>{MESSAGES[step]}</Text>
{primaryLabel ? (
<Pressable accessibilityRole="button" style={styles.primary} onPress={onCameraButton}>
<Text style={styles.primaryText}>{primaryLabel}</Text>
</Pressable>
) : null}
<Pressable accessibilityRole="button" style={styles.secondary} onPress={chooseFromPhotos}>
<Text style={styles.secondaryText}>Choose from your photos</Text>
</Pressable>
{photoUri ? (
<View style={styles.preview}>
<Image source={{ uri: photoUri }} style={styles.image} accessibilityLabel="Your referral letter photo" />
<Text style={styles.text}>Photo added. You can take or choose another to replace it.</Text>
</View>
) : null}
</View>
)
}
const styles = StyleSheet.create({
screen: { flex: 1, gap: 16, padding: 24, backgroundColor: '#ffffff' },
title: { fontSize: 22, fontWeight: '600', color: '#0b0c0e' },
text: { fontSize: 16, lineHeight: 24, color: '#2a2d33' },
camera: { flex: 1, minHeight: 320, borderRadius: 12, overflow: 'hidden' },
primary: { minHeight: 48, justifyContent: 'center', alignItems: 'center', borderRadius: 8, backgroundColor: '#0b0c0e' },
primaryText: { fontSize: 16, fontWeight: '600', color: '#ffffff' },
secondary: { minHeight: 48, justifyContent: 'center', alignItems: 'center' },
secondaryText: { fontSize: 16, color: '#0b0c0e', textDecorationLine: 'underline' },
preview: { gap: 8 },
image: { width: '100%', aspectRatio: 3 / 4, borderRadius: 8, backgroundColor: '#f1f2f4' },
})
TSXMake it the app's home screen. The SDK 58 template keeps its screens in src/app; replace the starter home screen with one that renders the component:
cat > src/app/index.tsx <<'TSX'
import { ReferralPhoto } from '@/referral/ReferralPhoto'
export default function Home() {
return <ReferralPhoto />
}
TSXThe buttons are at least 48 tall: Android's 48 dp touch-target recommendation, and above Apple's 44 pt minimum, and the header and buttons carry accessibility roles so VoiceOver and TalkBack announce them as such.
Check it worked
Bundle the app for Android. This compiles every file the screen imports, so a typo or a wrong import path fails here:
npx expo export --platform android --output-dir /tmp/referral-exportThe command ends with a line starting Exported: /tmp/referral-export, and the folder holds an Android bundle under _expo/static/js/android/.
Step 5 · Test every branch with the native modules mocked
Jest cannot open a camera, so the tests replace the two libraries with small stand-ins at the edge. useCameraPermissions returns whatever permission each test sets, the request function records that it was called, and CameraView becomes a plain view with a takePictureAsync method. The tests then check what matters to the patient: no system prompt before the explanation, a Settings link when asking again is impossible, and a working photo library path in every state.
Create src/referral/__tests__/ReferralPhoto.test.tsx:
cat > src/referral/__tests__/ReferralPhoto.test.tsx <<'TSX'
import { render, screen, userEvent } from '@testing-library/react-native'
import * as ImagePicker from 'expo-image-picker'
import { AppState, Linking } from 'react-native'
import type { CameraPermission } from '../camera-step'
import { ReferralPhoto } from '../ReferralPhoto'
let mockPermission: CameraPermission | null = null
const mockRequest = jest.fn()
const mockGet = jest.fn()
jest.mock('expo-camera', () => {
const React = require('react')
const { View } = require('react-native')
const CameraView = React.forwardRef((_props: object, ref: unknown) => {
React.useImperativeHandle(ref, () => ({
takePictureAsync: async () => ({ uri: 'file:///camera/letter.jpg' }),
}))
return React.createElement(View, { testID: 'camera-preview' })
})
return { CameraView, useCameraPermissions: () => [mockPermission, mockRequest, mockGet] }
})
jest.mock('expo-image-picker', () => ({
launchImageLibraryAsync: jest.fn(async () => ({ canceled: false, assets: [{ uri: 'file:///library/letter.jpg' }] })),
}))
const undetermined: CameraPermission = { granted: false, status: 'undetermined', canAskAgain: true }
const granted: CameraPermission = { granted: true, status: 'granted', canAskAgain: true }
const deniedOnce: CameraPermission = { granted: false, status: 'denied', canAskAgain: true }
const deniedForever: CameraPermission = { granted: false, status: 'denied', canAskAgain: false }
beforeEach(() => {
jest.clearAllMocks()
mockPermission = null
})
test('explains why before the system prompt appears', async () => {
mockPermission = undetermined
await render(<ReferralPhoto />)
expect(screen.getByText(/We only use it on this screen/)).toBeTruthy()
expect(mockRequest).not.toHaveBeenCalled()
})
test('asks on tap, opens the camera when allowed and shows the photo', async () => {
mockPermission = undetermined
mockRequest.mockImplementation(async () => {
mockPermission = granted
return granted
})
const user = userEvent.setup()
await render(<ReferralPhoto />)
await user.press(screen.getByRole('button', { name: 'Use camera' }))
expect(mockRequest).toHaveBeenCalledTimes(1)
expect(await screen.findByTestId('camera-preview')).toBeTruthy()
await user.press(screen.getByRole('button', { name: 'Take photo' }))
expect((await screen.findByLabelText('Your referral letter photo')).props.source).toEqual({ uri: 'file:///camera/letter.jpg' })
})
test('stays on the card when the patient says no', async () => {
mockPermission = undetermined
mockRequest.mockImplementation(async () => {
mockPermission = deniedOnce
return deniedOnce
})
const user = userEvent.setup()
await render(<ReferralPhoto />)
await user.press(screen.getByRole('button', { name: 'Use camera' }))
expect(screen.queryByTestId('camera-preview')).toBeNull()
})
test('offers another try after one refusal', async () => {
mockPermission = deniedOnce
await render(<ReferralPhoto />)
expect(screen.getByRole('button', { name: 'Try again' })).toBeTruthy()
})
test('links to Settings instead of asking when the system will not ask again', async () => {
mockPermission = deniedForever
const openSettings = jest.spyOn(Linking, 'openSettings').mockResolvedValue(undefined)
const user = userEvent.setup()
await render(<ReferralPhoto />)
expect(screen.getByText(/Turn it on in Settings/)).toBeTruthy()
await user.press(screen.getByRole('button', { name: 'Open settings' }))
expect(openSettings).toHaveBeenCalledTimes(1)
expect(mockRequest).not.toHaveBeenCalled()
})
test('lets the patient choose a photo without camera access', async () => {
mockPermission = deniedForever
const user = userEvent.setup()
await render(<ReferralPhoto />)
await user.press(screen.getByRole('button', { name: 'Choose from your photos' }))
expect(ImagePicker.launchImageLibraryAsync).toHaveBeenCalledWith({ mediaTypes: ['images'], quality: 0.6 })
expect(screen.getByLabelText('Your referral letter photo').props.source).toEqual({ uri: 'file:///library/letter.jpg' })
})
test('re-reads the permission when the patient comes back from Settings', async () => {
mockPermission = deniedForever
const addListener = jest.spyOn(AppState, 'addEventListener')
await render(<ReferralPhoto />)
const onChange = addListener.mock.calls.find(([type]) => type === 'change')?.[1]
onChange?.('active')
expect(mockGet).toHaveBeenCalledTimes(1)
})
TSXThe mock prefix on mockPermission, mockRequest and mockGet is required: Jest only lets a jest.mock factory refer to outside variables whose names start with mock. The factory also builds the stand-in camera with React.createElement rather than JSX for the same reason.
Check it worked
Run the whole referral test folder:
npx jest src/referral --ciJest reports Tests: 12 passed, 12 total across two suites. If the Settings test fails because openSettings was never called, check that onCameraButton handles blocked before it calls requestPermission.
Step 6 · Try the dialogs on a phone
The tests prove your logic; only a phone shows you the real dialogs. Start the development server and scan the QR code with Expo Go:
npx expo startExpo Go includes expo-camera and expo-image-picker, so the screen works there. It shows Expo Go's own prompt text, though, because your usage strings and blocked permissions only reach a native build. To see your wording, you need your own native build. There are two ways:
- A development build from EAS, as in Build and submit an app with EAS. This project does not have the pieces yet: add the dev client with
npx expo install expo-dev-client, sign in and link the project (eas login,eas init), runeas build:configureto createeas.json, theneas build --profile development --platform android(orios) and install the result. An iOS development build for a physical iPhone needs a paid Apple Developer account and the phone registered witheas device:create. - A local build with
npx expo run:android(Android Studio and a phone or emulator) ornpx expo run:ios(a Mac with Xcode, for the Simulator or a connected iPhone). These run prebuild, so your plugin settings apply.
Walk through each state in order. You need to reset the permission between runs, so keep the Settings app close:
- Fresh install: the card explains the camera before anything else. Tap "Use camera" and the system prompt appears. On iOS a development build shows your sentence under the title.
- Refuse. On Android the card changes to "Try again"; tap it and refuse a second time. On iOS one refusal is enough.
- The card now says camera access is off and shows "Open settings". Tap it, turn the camera on for the app, and switch back. The button changes to "Open camera" without restarting the app.
- Tap "Choose from your photos". The system photo picker opens with no permission prompt, and the chosen photo appears under the buttons.
To start again from a fresh prompt, uninstall the app and install it again; that resets its permissions on both platforms.
Check it worked
You have seen all four states on at least one platform (explain, then ask-again or blocked, then ready with the camera open, then a photo chosen from the library), the prompt in a development build shows your own sentence rather than "Allow … to access your camera", and in the Android app's permission settings only Camera is listed, with no Microphone, Files or Photos entry.
Next steps
- If this is your first Expo app, start with Create your first Expo app for the project layout and Expo Go.
- Design the explanation card and the Settings hand-off so they feel native on both platforms with Follow iOS and Android conventions in one design.
- Before release, review every permission and usage string in one pass, as in Get the Larkfield app ready for release.
- To change native settings that no plugin covers, read Change native iOS and Android settings with Expo config plugins and prebuild.
Related tutorials
- How to Create Your First React Native App with ExpoYou will create an Expo SDK 58 project with TypeScript, look at what the template gives you, run it on your phone or in a simulator, replace the home screen with a small counter of your own, and check from the command line that the project bundles and passes expo-doctor.
- Follow iOS and Android conventions in one designYou will have the Larkfield Clinic Pick a time screen as a pair of iOS and Android frames that share one brand, one set of words and one layout, and a "same or native" table that tells a developer which parts follow each platform and why.
- Get the Larkfield app ready for release: accessibility, versions and a Maestro smoke testYou will take the Larkfield Clinic Expo app through a release checklist, with tested accessible slot buttons, a version policy EAS enforces, the icon, splash and permissions checked by one script, and a Maestro flow that books an appointment, then hand it to EAS and clean up the series.
Need this done for you?
Padding does this work for growing companies, from the first diagnosis to a system that keeps working.
Get new tutorials