Android: chooseFromGallery crashes with EACCES permission denied on Android Scoped Storage (huawei)

Aperta
#63 0 commenti 1 reazione 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
55/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Tranquilla
Stack tecnologico
android, kotlin
Ambito
mobile-dev

Direzione di ricerca

Inizia da IONCAMRMediaProcessor.kt:81 e segui il risultato della galleria attraverso IONCAMRGalleryManager.kt:126 e :240, come identificato nello stack trace. Verifica come viene aperta l’immagine selezionata e conferma con la riproduzione su Huawei EMUI 12 che chooseFromGallery restituisce l’immagine senza un crash EACCES.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Current Behavior

@capacitor/camera: 8.2.1

Camera.getPhoto() works correctly.

Camera.chooseFromGallery() crashes on Android Huawei devices. (IOS and web ok)

Environment:

  • EMUI : 12.0.0
  • Huawei P30 Pro
  • modèle VOG-L29

Code:

Camera.chooseFromGallery({
quality: 80,
targetWidth: 600,
targetHeight: 600,
includeMetadata: false, (tried true)
})

Crash:

java.io.FileNotFoundException:
/storage/emulated/0/Pictures/IMG_20260119_112248.jpg:
open failed: EACCES (Permission denied)

Stacktrace:

IONCAMRMediaProcessor.createImageMediaResult
ExifInterface.

The plugin seems to access the absolute filesystem path instead of using ContentResolver/content:// URI.


FATAL EXCEPTION: DefaultDispatcher-worker-1
Process: com.xx.xxxx, PID: 32117
java.io.FileNotFoundException: /storage/emulated/0/Pictures/Screenshots/Screenshot_20260708_121645_com.huawei.android.launcher.jpg: open failed: EACCES (Permission denied)
at libcore.io.IoBridge.open(IoBridge.java:496)
at java.io.FileInputStream.(FileInputStream.java:159)
at java.io.FileInputStream.(FileInputStream.java:115)
at android.media.ExifInterface.initForFilename(ExifInterface.java:2363)
at android.media.ExifInterface.(ExifInterface.java:1415)
at io.ionic.libs.ioncameralib.processor.IONCAMRMediaProcessor.createImageMediaResult(IONCAMRMediaProcessor.kt:81)
at io.ionic.libs.ioncameralib.processor.IONCAMRMediaProcessor.createImageMediaResult$default(IONCAMRMediaProcessor.kt:65)
at io.ionic.libs.ioncameralib.manager.IONCAMRGalleryManager.createMediaResult(IONCAMRGalleryManager.kt:240)
at io.ionic.libs.ioncameralib.manager.IONCAMRGalleryManager.onChooseFromGalleryResult(IONCAMRGalleryManager.kt:126)
at com.capacitorjs.plugins.camera.IonCameraFlow$processResultFromGallery$1.invokeSuspend(IonCameraFlow.kt:901)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:34)
at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:104)
at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:584)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:811)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:715)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:702)
Suppressed: kotlinx.coroutines.internal.DiagnosticCoroutineContextException: [StandaloneCoroutine{Cancelling}@1efbba4, Dispatchers.Default]
Caused by: android.system.ErrnoException: open failed: EACCES (Permission denied)
at libcore.io.Linux.open(Native Method)
at libcore.io.ForwardingOs.open(ForwardingOs.java:167)
at libcore.io.BlockGuardOs.open(BlockGuardOs.java:252)
at libcore.io.ForwardingOs.open(ForwardingOs.java:167)
at android.app.ActivityThread$AndroidOs.open(ActivityThread.java:8464)
at libcore.io.IoBridge.open(IoBridge.java:482)
... 15 more

-------------------- (with the addition of service tag on manifest.xml ):

FATAL EXCEPTION: DefaultDispatcher-worker-2
Process: com.xxx.xxxxx, PID: 3638
java.io.FileNotFoundException: /storage/emulated/0/Pictures/Screenshots/Screenshot_20260708_121645_com.huawei.android.launcher.jpg: open failed: EACCES (Permission denied)
at libcore.io.IoBridge.open(IoBridge.java:496)
at java.io.FileInputStream.(FileInputStream.java:159)
at java.io.FileInputStream.(FileInputStream.java:115)
at android.media.ExifInterface.initForFilename(ExifInterface.java:2363)
at android.media.ExifInterface.(ExifInterface.java:1415)
at io.ionic.libs.ioncameralib.processor.IONCAMRMediaProcessor.createImageMediaResult(IONCAMRMediaProcessor.kt:81)
at io.ionic.libs.ioncameralib.processor.IONCAMRMediaProcessor.createImageMediaResult$default(IONCAMRMediaProcessor.kt:65)
at io.ionic.libs.ioncameralib.manager.IONCAMRGalleryManager.createMediaResult(IONCAMRGalleryManager.kt:240)
at io.ionic.libs.ioncameralib.manager.IONCAMRGalleryManager.onChooseFromGalleryResult(IONCAMRGalleryManager.kt:126)
at com.capacitorjs.plugins.camera.IonCameraFlow$processResultFromGallery$1.invokeSuspend(IonCameraFlow.kt:901)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:34)
at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:104)
at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:584)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:811)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:715)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:702)
Suppressed: kotlinx.coroutines.internal.DiagnosticCoroutineContextException: [StandaloneCoroutine{Cancelling}@2d03a37, Dispatchers.Default]
Caused by: android.system.ErrnoException: open failed: EACCES (Permission denied)
at libcore.io.Linux.open(Native Method)
at libcore.io.ForwardingOs.open(ForwardingOs.java:167)
at libcore.io.BlockGuardOs.open(BlockGuardOs.java:252)
at libcore.io.ForwardingOs.open(ForwardingOs.java:167)
at android.app.ActivityThread$AndroidOs.open(ActivityThread.java:8464)
at libcore.io.IoBridge.open(IoBridge.java:482)
... 15 more

Expected Behavior

When selecting an image from the gallery with Camera.chooseFromGallery(), the plugin should successfully return the selected image without crashing.

The plugin should handle Android Scoped Storage correctly by using the content URI provided by Android (ContentResolver/content:// URI) instead of trying to access the image through an absolute filesystem path.

Reproduction
  1. Install the app on an Android Huawei device with EMUI 12.
  2. Use @capacitor/camera version 8.2.1.
  3. Call: Camera.chooseFromGallery({ quality: 80, targetWidth: 600, targetHeight: 600, includeMetadata: false });
  4. Select an existing image from the gallery.
  5. The application crashes. The issue does not happen with: - Camera.getPhoto({ source: CameraSource.Photos }) -

iOS and Web : ok

Screenshots / Media

No response

Environment Details
Latest Dependencies:

  @capacitor/cli: 8.4.2
  @capacitor/core: 8.4.2
  @capacitor/android: 8.4.2
  @capacitor/ios: 8.4.2

Installed Dependencies:

  @capacitor/cli: 8.4.1
  @capacitor/core: 8.4.1
  @capacitor/android: 8.4.1
  @capacitor/ios: 8.4.1


  @capacitor/camera": "^8.2.1"
  node 22

    minSdkVersion = 24
    compileSdkVersion = 36
    targetSdkVersion = 36
    androidxActivityVersion = '1.11.0'
    androidxAppCompatVersion = '1.7.1'
    androidxCoordinatorLayoutVersion = '1.3.0'
    androidxCoreVersion = '1.17.0'
    androidxFragmentVersion = '1.8.9'
    coreSplashScreenVersion = '1.2.0'
    androidxWebkitVersion = '1.14.0'
    junitVersion = '4.13.2'
    androidxJunitVersion = '1.3.0'
    androidxEspressoCoreVersion = '3.7.0'
    cordovaAndroidVersion = '14.0.1'
Versions Affected

8.2.1

Platforms Affected
  • iOS
  • Android
  • Web
Notes / Comments

I suspect the issue is related to Huawei EMUI Scoped Storage handling.

The selected image seems to be returned as a filesystem path:
/storage/emulated/0/Pictures/...

instead of being processed through a content URI.

Android's MediaStore/Photo Picker should probably be accessed through ContentResolver to avoid permission issues.

Lingua principale
TypeScript
Stelle
6
Fork
3
Merge medio
2g 18h
PR unite (30g)
6

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di ionic-team/capacitor-camera

Tutte le issue di ionic-team/capacitor-camera

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.