React Native course · Module 11: Device and sensors

expo-device - Device information

1 min read ·
In this lesson3

Welcome to the Sensor Laboratory! Discover the capabilities of the device!

Installation

npx expo install expo-device

Device information

import * as Device from 'expo-device';

console.log('Brand:', Device.brand);           // "Apple", "Samsung"
console.log('Model:', Device.modelName);       // "iPhone 14 Pro"
console.log('OS:', Device.osName);             // "iOS", "Android"
console.log('OS Version:', Device.osVersion);  // "16.0"
console.log('Real device:', Device.isDevice);
console.log('Type:', Device.deviceType);       // PHONE, TABLET, DESKTOP

// Check if running on simulator
if (!Device.isDevice) {
  console.log('Running on simulator');
}

expo-constants

npx expo install expo-constants
import Constants from 'expo-constants';

console.log('App name:', Constants.expoConfig?.name);
console.log('Version:', Constants.expoConfig?.version);
console.log('Platform:', Constants.platform);
console.log('Status bar height:', Constants.statusBarHeight);
console.log('System fonts:', Constants.systemFonts);
Code for this lesson: App.tsx
import React from 'react';
import { View, Text, StyleSheet } from 'react-native';
import * as Device from 'expo-device';
import Constants from 'expo-constants';

export default function App() {
  // TODO: read the device brand from Device.brand
  const brand = '';
  // TODO: read the model name from Device.modelName
  const model = '';
  // TODO: read the OS name from Device.osName
  const osName = '';
  // TODO: check whether this is a physical device (Device.isDevice returns true/false)
  const isRealDevice = false;
  // TODO: get the app name from Constants.expoConfig?.name
  const appName = '';

  return (
    <View style={styles.container}>
      <Text style={styles.title}>Sensor Laboratory</Text>
      <Text style={styles.row}>Brand: {brand}</Text>
      <Text style={styles.row}>Model: {model}</Text>
      <Text style={styles.row}>System: {osName}</Text>
      <Text style={styles.row}>
        Physical device: {isRealDevice ? 'yes' : 'no'}
      </Text>
      <Text style={styles.row}>App: {appName}</Text>
    </View>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    paddingHorizontal: 24,
    backgroundColor: '#1a5276',
  },
  title: {
    fontSize: 22,
    color: '#fff',
    marginBottom: 16,
  },
  row: {
    fontSize: 16,
    color: '#aed6f1',
    marginBottom: 8,
  },
});

Docs entries used in this lesson

Spotted a mistake in this lesson?

Check yourself

Answer the questions from this lesson. Pick an answer to see right away whether it is correct.

  1. 1. How do you install expo-device?

  2. 2. What does Device.isDevice return?

These are 2 of 5 questions for this lesson. Solve the rest in the game.

Hands-on tasks in the game

  • Code editor

    Complete the code using expo-device.

  1. QuestionInstalling expo-device
  2. QuestionDevice.isDevice
  3. QuestionDevice.brand
  4. QuestionDevice.deviceType
  5. Questionexpo-constants
  6. Coding taskDevice info

Useful articles