"Error 201, the camera did not return an image" on Samsung device, Android 8.0

according to the release notes the camera bug for Android 10 already was fixed in February

[Bug] Fixed an issue on Android 10 that prevented the Camera component from working correctly.

I don’t remember, if I tested to take a picture since then, but now I get the error “Error 201, the camera did not return an image” on Samsung Galaxy A(2017) running on Android 8.0 while testing in the companion app (latest version 2.58) as well as after building the app.

example project attached
cameratest.aia (2.0 KB)


Taifun

I checked it on a Samsung Galaxy A3 (2017) (Android 8.0.0), Model-No: SM-A320FL.
No issues with Companion & APK.

thank you @Anke… very strange…
Taifun

Maybe a local problem with http://ai2.appinventor.mit.edu/, try this APK:

thank you again…unfortunately same issue with that apk…
Taifun

Really strange, perhaps your device is infected with the coronavirus. :wink:

1 Like

So I just tried with my Samsung S8Active Running Pie (9.0) and it worked both in the Companion and in a packaged APK. Looking at the source code of the Camera component doesn’t really give us much clue. Basically the Camera returned an image file of zero length.

If you can use a USB debugging cable (or network debugging) you can look at the “logcat” to see if there are any clues there.

Another thing to try is to simply restart your phone. A few (OS) updates ago my camera would “hang” until I restarted my phone.

I was able to reproduce this issue now:
You have most likely deleted the “Pictures” folder:
/storage/emulated/0/Pictures

Apparently this is not created automatically by the camera component.
I get exactly the same error on my Galaxy A3 when deleting this folder.

2 Likes

To catch this issue (missing “Pictures” folder"), this is my approach:
(I put an empty text file: dummy.txt in the assets)

cameraTest2.aia (34.1 KB)

1 Like

indeed… thank you very much @Anke, you are a wizard!
Taifun

Another observation: @ewpatton
If I install the app on a device with API=18 (Android 4.3), the Pictures folder is created by the Camera component. On devices with API>20 this folder is NOT created.

(For testing, I removed the Images folder on the test devices beforehand.)

1 Like

I think the folder should be created if it doesn’t exist.
Apparently that was also the opinion of the App Inventor team when the Camera component was introduced, as I could already demonstrate for devices with Android 4.3 (e.g. Samsung Galaxy S3).

@Anke Actually, it’s not quite that. The Camera component hands the Camera app a file URL pointing to where it would like the picture to be written. My guess is that previously, most distributions of Android were using the same core code for their Camera apps, and this code handled the missing directory by creating it (App Inventor doesn’t create the directory). It may be that the Camera app in that particular version of Android from Samsung doesn’t do this. Alternatively, starting with Android 7.0 Nougat, you can’t hand out file URLs like candy any more, so on Nougat and higher we hand a content URI instead and the camera writes to that. My guess is that this is solvable by creating the directory on our end so that we no longer rely on the phone’s camera app to do the right thing, since not everyone does.

2 Likes

I’ve filed an issue:

2 Likes

Thanks for the detailed explanations!

The same problem with Kodular, by the way, but it’s quite easy to fix / work around it, since the File component has a Create.Directory method:

1 Like

I tested it now also on these devices:

  • Galaxy Note 8 (Android 9) and there is no OK button after taking a picture
  • Xiaomi Redmi Note 5 (Android 9) there is an OK button, but after pressing it I get no image
  • Galaxy Note 3 (Android 5) I get the same error as on the Galaxy A3 (like Taifun)
  • Motorola Moto G (Android 5.1) same error as before
  • Galaxy S6 (Android 7) as before
  • OnePlus 6 (Android 10) I get an hook (instead of OK) which is not clickable.

On all devices the Pictures folder is not created.

1 Like

Sporadically I have this problem with Xiaomi redmi6
I would like to share with you or those I have problems with.

On LG and Motorola devices, it does not have a Folder Pictures default, I am using an extension that allows me to save a photo in the other directory, in my case on DCIM, problem solved.

I have a test on 150 devices, of which 150 devices, 20% are xiaomi, of those 20% I have a single problem with a single redmi 6.
This problem is:
1-Click to open camera (OK)
2-Click to take photo (OK)
when bringing the photo to the component image, or the object’s camera, it opens again as you clicked on the button to click on the photo, as if everything restarted

In my case, I’m working to search my code for error, but the process is simple.
1 - button to open the camera.
2 - an image component to receive a photo.
so I’m confused, but I keep trying

Did you try this?

yes,

I solved 99% of the problems just by not using the Pictures folder and using DCIM,
but even so, for security, my application creates the Pictures folder.

i am having problem on 1 of 20 xiaomi redmi 6. only 1 still has the problem of not capturing a photo.

I will receive this phone here next week to analyze it, when I know of a solution I will let my friends know.

A question I thought:
Is it possible for the DCIM directory to be busy? stuck in the process?
example: I take a photo using the camera component, does this component not release a folder where the photo was recorded?
and how does the component reset on the camera and not get a picture?

Because accidentally discovering this on LG and Motorola phones, when I used the PICTURES folder, these two phone models had the defect of not capturing the photo, I found that they do not use this folder by default, and at the time the camera component did not create the folder alone.

One day I luckily created this folder on the phone I was testing and the app worked normally, so today I use the DCIM folder and still check if it doesn’t exist I do create it.