Lucastegano X
Lucastegano X

Reputation: 5

Why is android.media.action.IMAGE_CAPTUR not saving the picture?

:)

Basically I am writing a termux bash script to take care of my purchases in real life. And rn I am trying to automatically ask for a photo of a grocery ticket if the program detects the purchase was a grocery.

For that matter(taking the picture) I am trying to use the activity android.media.action.IMAGE_CAPTURE. Using chatgpt(I know, just hold with me for a second) I have found that you can pass " -e output URI" to it, and it should store the picture in there. I tried passing a file URI, and it didn't seem to work at first as it wasn't able to create a file.

I tried to create an empty file and then have the activity to re write it. And it worked.

The command I tried after creating the file was this:

am start -a android.media.action.IMAGE_CAPTURE -e output file:///data/data/com.termux/files/home/moneybook/test.png

It worked. However, I did this interactively as I was trying stuff out. When I tried to replicate it later in the day, I couldn't do it, and I don't know why. I tried taking a look into the bash history to see what was different, but there's a gargantuan gap of time in there; stuff I did before checking the history, down to a few days before were not there.

I tried writing into the sdcard to see if now it was a matter of the activity not being able to write in termux's storage somehow. But it couldn't do it either.

cd /storage/emulated/0 touch test.png am start -a android.media.action.IMAGE_CAPTURE -e output 'file///storage/emulated/0/test.png'

Catting the file prints nothing.

I heard that android fostered the use of content URI's instead of file URI's for security reasons. So I tried using one of those... I tried using a content URI from miMix(a file explorer)...

am start -a android.media.action.IMAGE_CAPTURE -e output 'content://com.mixplorer.silver.file/525!/test.png'

Nothing either. I tried writing to a new file called test2 this way. Nothing either.

Update @CommonsWare suggested that it might be a rights problem. And it made some sense since "recent" android versions limit the writing directly to the "home directory"(/storage/emulated/0). So I with /storage/emulated/0/DCIM/Camera(which the camera is supposed to have write rights onto) and it didn't work either. Not writing to a new file, nor overwriting an existing file.

I find it weird, because when I did get it, I have got the permission prompt from android like "Can this app use the camera every time, once or not?" And I was able to write into termux's storage directly... ––––––

I don't know what is going on... I would appreciate some insights or thoughts into this. My android version is 11, I am on miui 12.

In any case, thanks for reading :)

Upvotes: 0

Views: 40

Answers (0)

Related Questions