Android Question [Solved] Firing camera without user intervention

rabbitBUSH

Well-Known Member
Licensed User
I've found a bunch of items that help with taking photos BUT with user pressing the button.

I need to have the APP open the phone and take a photo - unattended - in the manner that a webcam would periodically take a photo.

So this isn't a web app - I just need a slave phone to take a photo/s in obedience to a timer.

1. Is this possible?
2. Haven't found any guidance (except one very old post which didn't really assist) in my searches.

Thanks in advance for any assistance.
 

drgottjr

Well-Known Member
Licensed User
Longtime User
there is nothing to "twist around a bit"; focusandtakepicture is a method
in the camex class.

and pressing a button to take a picture can also be automated if you can't
get your head around focusandtakepicture. but it is a slightlly different
approach, although the end result can be the same either way. try both.
they both involve setting a timer. (you are aware that you can cause a
button to click programatically, right?)

examples are meant to be modified. i don't know where you stand
with your camera app. if you have a camera app example that you're
working with, the odds are you also have the camex class. no need to
go looking for it. if you're starting from scratch, just copy and paste
the camex class from some example into your app. or modify the
example to suit your needs. i still use the same basic camera example
with erel's camex class from years ago. i just modify as needed. sometimes
i use user action, sometimes focusandtakepicture, sometimes capturing
frames from the preview. but the camera setup is through the camex class.

after the camera is ready, you set a timer for, eg, every 10 seconds. when the
timer runs down, it raises its "tick" event. in the tick event, you call
focusandtakepicture or button1_click. your call. after that occurs, you start the
camera preview, and enable the timer again, ad nauseam:

B4X:
dim timer1 as timer   (in process_globals)
timer1.initialize("timer1",10000)
timer1.enabled = false

'once camera is ready
timer1.enabled = true

sub timer1_tick
   timer1.enable = false
   camex.focusandtakepicture   (or you could call button1_click if you have such a button)
   ' do whatever else you want...
   camex.startpreview
   timer1.enable = true

end sub

sub button1_click
   camex.takepicture
end sub

sub activity_pause
   camex.release
   timer1.enabled = false
end sub


note: you need to set the focus depending on whether you're going to use focusandtakepicture
or button1_click. they work differently.
 
Last edited:
Upvote 1

drgottjr

Well-Known Member
Licensed User
Longtime User
erel's camex2 class will set up the camera. the original camera api is still very useful.
once the camera has been initialized, you set a timer. when the timer runs down,
you call the focusandtakepicture method and set the timer again. (those steps are
done in code, obviously.) you decide on the size of the image, but the whole
process couldn't be much easier.

you don't say whether you've ever written a camera-related app before or what
happens to each picture after it's been taken. i'm afraid to ask.
 
Upvote 0

rabbitBUSH

Well-Known Member
Licensed User
Thanks for the response - nice to hear from you.

you don't say whether you've ever written a camera-related app before or what
happens to each picture after it's been taken. i'm afraid to ask.
HA HA - That's a sneaky question. Just going onto SD - though you've given me an idea for some future "lucrative" project :cool:.

erel's camex2 class
Although I have script from somewhere here that has this in it - I haven't found the download point in the searching.
you set a timer. when the timer runs down,
got all that from one of Erel's examples (not the one showing INTENT and invoking the default camera app). So, I have the timer running and also some intended code for writing to SD or just internal storage running nicely. When that hits the timer trigger it pops a toast, and, that should be the point at which the photo should be taken.

logically.

but the whole
process couldn't be much easier.
Oh yeah - on the surface of it. What is eluding me is by-passing the button push - which might be about twisting focusandtakepicture around a bit.

So, we appear to be both on the same logic and direction - just getting past the need for human intervention (pressing the camera trigger button) part seems to be illusive.
 
Last edited:
Upvote 0

rabbitBUSH

Well-Known Member
Licensed User
check this
Thanks for the response - great to hear from you as well.

I am looking at your zip and just getting some things going to run it.

edits later on from first posting time :
although if this is the real trick to it - wow:
Sub btnTakePicture_Click
    btnTakePicture.Enabled = False
    camera1.TakePicture
End Sub

Turns out, after studying the code -> one still has to press the button to get a photo.
 
Last edited:
Upvote 0

rabbitBUSH

Well-Known Member
Licensed User
i don't know where you stand
Been heading along the path you have indicated - should get there tonight if time permits.

(you are aware that you can cause a
button to click programatically, right?)
Never really thought about it until now.

I have everything as you indicate and suggest - it's just been the 'fucusandtakepicture' bit stalling it - which you have clarified now for me.

@drgottjr : thanks a great deal for taking the time and the code snippet - I'm sure I'll wrap it up soon.

I'm going to mark this solved - much appreciated.
 
Upvote 0
Top