Device & ShipExtra· 40 min read

Device Features: Camera & Permissions

Phones have a camera, GPS and more — but you must ask the user for permission first.

What you will learn

  • Use an Expo module to reach the camera
  • Ask for permission before using it
  • Handle the case where permission is denied

The phone can do more than a browser

A real strength of mobile is the hardware: camera, photo library, location, contacts. Expo gives you ready-made modules for these. The golden rule: you must ask permission before touching anything private.

For picking a photo you install Expo Image Picker (one-time):

Install the Expo image picker module
npx expo install expo-image-picker

Note: Output: (Adds the image-picker module. Nothing visible yet.)

Ask, then open the picker

First request permission, then — only if granted — open the photo picker:

Request permission first, then launch the picker
import * as ImagePicker from 'expo-image-picker';

async function pickPhoto() {
  const perm = await ImagePicker.requestMediaLibraryPermissionsAsync();
  if (perm.status !== 'granted') {
    console.log('Permission denied');
    return;
  }
  const result = await ImagePicker.launchImageLibraryAsync();
  if (!result.canceled) {
    console.log('Picked:', result.assets[0].uri);
  }
}

Note: Output (when the user allows and picks a photo): Picked: file:///path/to/photo.jpg If the user taps "Don’t Allow", you see "Permission denied" instead — and you must not open the picker.

  • Always request permission before using a private feature.
  • Check the status — never assume it was granted.
  • If denied, show a kind message; do not crash or nag endlessly.

The pattern is always the same three steps, whatever the feature: ask for permission, check you got it, then use the feature. Camera, location and contacts all follow it.

The whole permission flow, step by step

Here is exactly what happens when the user taps your "Pick photo" button, in order:

  1. The user taps the button, which runs your pickPhoto function.
  2. Ask: await ImagePicker.requestMediaLibraryPermissionsAsync() shows the phone’s own pop-up: "Allow this app to access your photos?".
  3. The user taps Allow or Don’t Allow. The result comes back as an object stored in perm, and perm.status is the string 'granted' or 'denied'.
  4. Check: the if (perm.status !== 'granted') line tests that string. If it is not 'granted', you log "Permission denied" and return — stopping before you ever open the picker.
  5. Use: only if permission was granted, await ImagePicker.launchImageLibraryAsync() opens the photo gallery so the user can choose a picture.
  6. The user either picks a photo or taps cancel. result.canceled tells you which: the if (!result.canceled) line runs only when they actually chose one.
  7. When they did pick, result.assets[0].uri is the address of the chosen photo (here logged as Picked: file:///path/to/photo.jpg) — ready to show in an Image.

What works where

A common beginner trip-up is expecting every device feature to run inside Expo Go. Many do; a few need a heavier setup called a development build. Here is the quick guide:

FeatureWorks in Expo Go?
Pick a photo from the libraryYes
Get the device location (GPS)Yes
Read contacts / notificationsYes
A fully custom in-app cameraOften needs a development build

Watch out: Some native features (like a custom in-app camera) do not work fully in Expo Go and need a development build — a one-time custom version of the Expo Go app for your project. Photo picking and location work in plain Expo Go, which is why they are great to learn with first.

Tip: The picked photo gives you a uri string. Feed it straight into an Image: <Image source={{ uri }} style={{ width: 200, height: 200 }} /> to show it on screen.

Q. What must you always do before using the camera or photo library?

Answer: Private device features require asking permission first and checking the status — if denied, you must not proceed.

✍️ Practice

  1. Add a "Pick photo" button that requests permission and logs the chosen uri.
  2. Show the picked photo on screen with an Image using its uri.

🏠 Homework

  1. Build a screen with a "Choose Avatar" button that asks permission, lets the user pick a photo, and displays it.
Want to learn this with a mentor?

CodingClave runs guided, project-based training (28-day, 45-day & 6-month batches).

Explore Training →