Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

expo-sdcard-detector

abelpz94MIT1.0.0TypeScript support: included

Expo plugin to detect SD card storage paths on Android

expo, react-native, expo-plugin, sdcard, android, filesystem

readme

expo-sdcard-detector

An Expo config plugin and native module to detect SD card storage paths on Android devices. This module helps you access external storage paths, particularly useful for applications that need to interact with SD cards or external storage.

Features

  • 🔍 Detect all external storage paths on Android devices
  • 📱 Compatible with Expo and React Native projects
  • 🔧 Easy to integrate with existing Expo applications
  • 📦 TypeScript support included
  • 🛡️ Safe to use on iOS (returns empty array)

Requirements

  • Expo SDK 49 or higher
  • React Native 0.72 or higher
  • Android device with external storage support

Installation

npm install expo-sdcard-detector
# or
yarn add expo-sdcard-detector

Configuration

Add the plugin to your app.config.js or app.config.ts:

module.exports = {
  name: "my-app",
  plugins: ["expo-sdcard-detector"]
};

Usage

import { getExternalStoragePaths } from 'expo-sdcard-detector/native';

// Get all external storage paths
const paths = await getExternalStoragePaths();
console.log(paths);
// Example output on Android: ['/storage/emulated/0', '/storage/sdcard1']
// Example output on iOS: []

Example: Write to SD card

import { getExternalStoragePaths } from 'expo-sdcard-detector/native';
import * as FileSystem from 'expo-file-system';

const [sdPath] = await getExternalStoragePaths();       // e.g. "/storage/sdcard1/Android/data/…/files"
if (sdPath) {
  const fileUri = `file://${sdPath}/myFolder/hello.txt`;

  await FileSystem.makeDirectoryAsync(`file://${sdPath}/myFolder`, { intermediates: true });
  await FileSystem.writeAsStringAsync(fileUri, 'Hello SD-card!');

  const info = await FileSystem.getInfoAsync(fileUri);
  console.log(info);
}

Caveats / good to know

  • The function only returns paths for removable volumes; the internal storage path (/storage/emulated/0/…) is already available via FileSystem.documentDirectory.
  • iOS will always return an empty array ([]).
  • If you need to touch folders outside your app’s sandbox (e.g. the root of the SD-card or the user’s DCIM directory) you’ll have to use the Storage Access Framework (expo-storage-access-framework) or request the MANAGE_EXTERNAL_STORAGE permission on Android 11+, because Expo FileSystem alone may not bypass scoped-storage rules.

API Reference

getExternalStoragePaths()

Returns a Promise that resolves to an array of strings containing the paths to external storage devices.

  • Android: Returns an array of external storage paths (including SD card paths)
  • iOS: Returns an empty array []

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

MIT