Skip to content

tutorial3-camera-control sample fails to save captured image on modern android #24590

@asmorkalov

Description

@asmorkalov

System Information

Android 11+

Detailed description

Logcat:

11-24 13:36:57.184  3749  3749 E PictureDemo: Exception in photoCallback
11-24 13:36:57.184  3749  3749 E PictureDemo: java.io.FileNotFoundException: /storage/emulated/0/Pictures/sample_picture_2023-11-24_13-36-56.jpg: open failed: EACCES (Permission denied)
11-24 13:36:57.184  3749  3749 E PictureDemo: 	at libcore.io.IoBridge.open(IoBridge.java:496)
11-24 13:36:57.184  3749  3749 E PictureDemo: 	at java.io.FileOutputStream.<init>(FileOutputStream.java:235)
11-24 13:36:57.184  3749  3749 E PictureDemo: 	at java.io.FileOutputStream.<init>(FileOutputStream.java:125)
11-24 13:36:57.184  3749  3749 E PictureDemo: 	at org.opencv.samples.tutorial3.Tutorial3View.onPictureTaken(Tutorial3View.java:77)
11-24 13:36:57.184  3749  3749 E PictureDemo: 	at android.hardware.Camera$EventHandler.handleMessage(Camera.java:1295)
11-24 13:36:57.184  3749  3749 E PictureDemo: 	at android.os.Handler.dispatchMessage(Handler.java:107)
11-24 13:36:57.184  3749  3749 E PictureDemo: 	at android.os.Looper.loop(Looper.java:227)
11-24 13:36:57.184  3749  3749 E PictureDemo: 	at android.app.ActivityThread.main(ActivityThread.java:7582)
11-24 13:36:57.184  3749  3749 E PictureDemo: 	at java.lang.reflect.Method.invoke(Native Method)
11-24 13:36:57.184  3749  3749 E PictureDemo: 	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:539)
11-24 13:36:57.184  3749  3749 E PictureDemo: 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:953)
11-24 13:36:57.184  3749  3749 E PictureDemo: Caused by: android.system.ErrnoException: open failed: EACCES (Permission denied)
11-24 13:36:57.184  3749  3749 E PictureDemo: 	at libcore.io.Linux.open(Native Method)
11-24 13:36:57.184  3749  3749 E PictureDemo: 	at libcore.io.ForwardingOs.open(ForwardingOs.java:167)
11-24 13:36:57.184  3749  3749 E PictureDemo: 	at libcore.io.BlockGuardOs.open(BlockGuardOs.java:252)
11-24 13:36:57.184  3749  3749 E PictureDemo: 	at libcore.io.ForwardingOs.open(ForwardingOs.java:167)
11-24 13:36:57.184  3749  3749 E PictureDemo: 	at android.app.ActivityThread$AndroidOs.open(ActivityThread.java:7481)
11-24 13:36:57.184  3749  3749 E PictureDemo: 	at libcore.io.IoBridge.open(IoBridge.java:482)

Related: https://stackoverflow.com/questions/63364476/requestlegacyexternalstorage-is-not-working-in-android-11-api-30

Steps to reproduce

Run the app on phone or tablet, tap on display and check for image and logcat errors

Issue submission checklist

  • I report the issue, it's not a question
  • I checked the problem with documentation, FAQ, open issues, forum.opencv.org, Stack Overflow, etc and have not found any solution
  • I updated to the latest OpenCV version and the issue is still there
  • There is reproducer code and related data files (videos, images, onnx, etc)

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions