Exception occurred while executing exported method getDocumentAsync on module ExpoDocumentPicker

Viewed 374

I am making an app using React Native and Expo.

My goal

You can import some audio from your cellphone and when you press a button this button plays the audio.

I am using Expo, so I installed ExpoDocumentPicker. I first tried this:

 DocumentPicker.getDocumentAsync();

And this code worked very well to pick any document from the cellphone. But I prefer to have just the audio option to pick, for the agility and prevent future errors.

So I looked into the ExpoDocumentPicker docs and I found the supposed "solution" of my problems (I first tried searching on Youtube and Google, but nothing worked to me).

And I tried this code that I found at the docs:

    await DocumentPicker.getDocumentAsync
    ({
      type: ["audio/*"],
    });

The Expected behavior

When the user presses the button the app open the cellphone file explorer just for audios

What happened

This worked very well on the web. But then I tried on my Android cellphone and doesn't work.

I got the following error message:

[Unhandled promise rejection: Error: Encountered an exception while calling native method: Exception occurred while executing exported method getDocumentAsync on module ExpoDocumentPicker: java.util.ArrayList cannot 
be cast to java.lang.String]

And the complete error log:

[Unhandled promise rejection: Error: Encountered an exception while calling native method: Exception occurred while executing exported method getDocumentAsync on module ExpoDocumentPicker: java.util.ArrayList cannot 
be cast to java.lang.String]
- node_modules\react-native\Libraries\BatchedBridge\NativeModules.js:103:50 in promiseMethodWrapper
- node_modules\@unimodules\react-native-adapter\build\NativeModulesProxy.native.js:15:23 in moduleName.methodInfo.name
- node_modules\expo-document-picker\build\index.js:2:7 in getDocumentAsync
- node_modules\regenerator-runtime\runtime.js:45:36 in tryCatch
- node_modules\regenerator-runtime\runtime.js:274:29 in invoke
- node_modules\regenerator-runtime\runtime.js:45:36 in tryCatch
- node_modules\regenerator-runtime\runtime.js:135:27 in invoke
- node_modules\regenerator-runtime\runtime.js:170:16 in PromiseImpl$argument_0
- node_modules\promise\setimmediate\core.js:45:6 in tryCallTwo
- node_modules\promise\setimmediate\core.js:200:22 in doResolve
- node_modules\promise\setimmediate\core.js:66:11 in Promise
- node_modules\regenerator-runtime\runtime.js:169:15 in callInvokeWithMethodAndArg
- node_modules\regenerator-runtime\runtime.js:192:38 in enqueue
- node_modules\regenerator-runtime\runtime.js:219:8 in exports.async
* http://192.168.0.7:19001/node_modules%5Cexpo%5CAppEntry.bundle?platform=android&dev=true&minify=false&hot=false:136666:37 in getDocumentAsync
* src\pages\start-page\index.js:42:2 in teste
- node_modules\regenerator-runtime\runtime.js:45:36 in tryCatch
- node_modules\regenerator-runtime\runtime.js:274:29 in invoke
- node_modules\regenerator-runtime\runtime.js:45:36 in tryCatch
- node_modules\regenerator-runtime\runtime.js:135:27 in invoke
- node_modules\regenerator-runtime\runtime.js:145:18 in PromiseImpl.resolve.then$argument_0
- node_modules\promise\setimmediate\core.js:37:13 in tryCallOne
- node_modules\promise\setimmediate\core.js:123:24 in setImmediate$argument_0
- node_modules\react-native\Libraries\Core\Timers\JSTimers.js:135:14 in _callTimer
- node_modules\react-native\Libraries\Core\Timers\JSTimers.js:183:16 in _callImmediatesPass
- node_modules\react-native\Libraries\Core\Timers\JSTimers.js:446:30 in callImmediates
* [native code]:null in callImmediates
- node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:396:6 in __callImmediates
- node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:144:6 in __guard$argument_0
- node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:373:10 in __guard
- node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:143:4 in flushedQueue
* [native code]:null in flushedQueue
* [native code]:null in invokeCallbackAndReturnFlushedQueue

What I thought the error were relationed

I thought that this error was because I wasn't asking permission to the user, so I downloaded ExpoPermissions and I add these lines at the function:

await Permissions.askAsync(
    Permissions.CAMERA_ROLL
)

But these lines don't changed anything...

My current code

And this are my current code that still don't working:

  async function onBtnPress(){
    await Permissions.askAsync(
      Permissions.CAMERA_ROLL
    )

    await DocumentPicker.getDocumentAsync
    ({
      type: ["audio/*"],
    });
  }
0 Answers
Related