Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

getting an error while trying to pick a directory using expo document picker in react-native

New member
Joined
Feb 14, 2023
Messages
10
hay guys, i am making a react native app with expo and i am using "expo document picker" module to access the folder in the device by clicking on the button in my app , i am getting this error in my terminal --

Code:
LOG  [Error: Encountered an exception while calling native method: Exception occurred while executing exported method getDocumentAsync on module ExpoDocumentPicker: No Activity found to handle Intent { act=android.intent.action.OPEN_DOCUMENT cat=[android.intent.category.OPENABLE] typ=directory }]
this is my code---

Code:
const pickDirectory = async () => {
    console.log("hi!!!!!");
    try {
      const permission =
        await FileSystem.StorageAccessFramework.requestDirectoryPermissionsAsync();
      if (permission.granted) {
        const dir = await DocumentPicker.getDocumentAsync({
          copyToCacheDirectory:true,
          type: "directory",
        });
        // setSyncDirectory();
        console.log(dir);
      }
    } catch (error) {
      console.log(error);
    }
  };
 
New member
Joined
Feb 14, 2023
Messages
6
The error you are seeing is because the DocumentPicker.getDocumentAsync() method can't find an app on your device that can open a folder.

The DocumentPicker module is meant for selecting and opening documents, not folders. If you want to let users choose a folder, you can use FileSystem.StorageAccessFramework instead. This allows you to request access to a directory and perform file operations like reading and writing files.

Code:
import * as FileSystem from 'expo-file-system';

const pickDirectory = async () => {
  console.log("hi!!!!!");
  try {
    const permission = await FileSystem.requestDirectoryPermissionsAsync();
    if (permission.granted) {
      const dir = await FileSystem.StorageAccessFramework.browseForFolderAsync();
      console.log(dir);
    }
  } catch (error) {
    console.log(error);
  }
};

Note that the browseForFolderAsync() method is currently only available on Android, so if you need to support iOS as well, you will need to use a different method or library to allow the user to select a folder.
 
Top