Android Question Wired trigger for Android cell phone camera

MOGO

Member
New to Android programming and have searched the forum/web for an example without success. I would like to trigger Android cell phone to take a picture and email/text it using an externally generated pulse or switch closure. Motion detection won't work or I would just use a cellular trail camera! I know you can trigger a cell camera through the ear phone jack so I am thinking that is the fastest route to do this. Would really appreciate being pointed to any example code to start from.
 

JohnC

Expert
Licensed User
Longtime User
Since you need to create a B4A app to email the take picture anyway, instead of trying to trigger the "built-in" camera app to take the picture, your best bet is to simply add picture taking ability to the B4A app (using the camera lib), then you can take a picture (and email it) using almost any method you can think of because you will have FULL control over the camera process.
 
Last edited:
Upvote 0

MOGO

Member
Thanks for replying. Using the camera lib, I assume camera2, how would you trigger it ? I haven't found any where that has been implemented. Keyboard input, PIR, wifi, Bluetooth are not options here.
 
Upvote 0

JohnC

Expert
Licensed User
Longtime User
You initially mentioned you wanted to use a pulse of switch closure, so what action or condition needs to happen to trigger this pulse or switch closure?

I'm just trying to understand your exact application so I can come up with some ideas to do what you want.
 
Last edited:
Upvote 0

MOGO

Member
Thanks for your reply!! Motion activated sensors on trail cameras don't work because of several issues, mostly related to wind,. Even with the PIR sensor set to the minimum setting, a cellular trail camera sent over 6,000 pictures triggered by windy conditions. I'm trying use other remote sensors connected to a relay closure to trigger an Android camera and send photos. After more studying of options I think a relay activating bluetooth may be an option.
 
Upvote 0

JohnC

Expert
Licensed User
Longtime User
OK, now that I know what your application is, this opens up a lot of potential issues...

Usually trail cameras are designed to use very little power so that they can operate for days/weeks on a battery because there is no AC power outlet nearby.

So, will the device (that your B4A app will run on) be powered continuously using an AC power adapter or will it need to run on battery?

(depending on your answer, I will provide some potential issues and ideas)
 
Last edited:
Upvote 0

MOGO

Member
Thanks for the reply. The way I'm looking at doing this will give me the option of using a much smaller camera footprint and putting some distance between the camera and the trigger actuator. With 50' or so of separation I can find a way to hide a small solar panel and battery. Solar is not a problem out here where there isn't a tree for miles! I can use fence lines and stuff that blows into the fence lines, or looks like it did, to hide my components. That is a way to use the wind that causes so many problems with PIR sensors on trail cams. Trail cams stick out like a sore thumb in this terrain.
 
Upvote 0

JohnC

Expert
Licensed User
Longtime User
Well, we have two parts to this project: The "trigger" and the "camera". And how this is done depends on the power available.

Unless you tell me otherwise, I'm assuming you found a new trigger mechanism that should eliminate false "wind" triggers (if not then I have some ideas to eliminate a lot of the false triggers using a combination of an PIR sensor and image motion detection)

You mentioned that this sensor can provide Switch Contacts or a Bluetooth "signal":

1) If power is not a concern because you have a big enough battery and solar panels, then you could write a B4A app that will keep the phone awake (KeepAlive or in standby) full time so it can receive the Bluetooth signal.

2) If power is a concern, then you might be able to use the "switch" closure contacts to simulate the headset button (in the headset jack) which in my limited testing can wake up a device from standby mode when triggered.

Then once you receive the trigger, you will use the Camera2 lib (https://www.b4x.com/android/forum/threads/camera2-new-camera-library.83855/) to take a picture and the NET lib (https://www.b4x.com/android/forum/threads/new-net-library-android-ftp-smtp-and-pop3.10892/) to email it to you.
 
Last edited:
Upvote 0

JohnC

Expert
Licensed User
Longtime User
I can use fence lines and stuff that blows into the fence lines, or looks like it did, to hide my components.
Wow, that is some smart animals you are trying to trick, or are they of the two-legged variety?;)
 
Upvote 0

MOGO

Member
The two legged camera thieves. Elk always tear the fences down where they normally cross. Antelope cross under fences in the same areas along their usual travel paths so game cameras are obvious hanging fence posts!

Thanks for the suggestions! I am definitely interested in " ideas to eliminate a lot of the false triggers using a combination of an PIR sensor and image motion detection" as that might be the solution.

I tried to use the "switch" closure contacts to simulate the headset button (in the headset jack)" because I thought that would be a quick and easy option. I got it to kind of work on an IPhone but didn't have any luck with the headphone button with the Android. Are there different kinds of headphones to look at? Not knowing the board level connections it is more difficult. THANKS AGAIN!!
 
Upvote 0

JohnC

Expert
Licensed User
Longtime User
The idea I have to try to limit the false triggers:

1) When the PIR triggers (because it sensed moving heat), have the app take 3-6 pictures in a row (like once a second)
2) Create or find a routine that compares two images and generates a number representing how different the two images are from one another (0=no difference, the higher the value, the more the difference).
3) Compare each image to the next.
4) If the formula comes back with close to "0" for the difference between the images (or less then some value that you determined), then that would mean there was no significant motion in the images, so ignore the PIR trigger event and do NOT email any images.
5) However, if the formula returns numbers that are higher then some threshold amount you set, then email the pictures because that would mean that; A) The PIR detected moving heat, and B) the formula confirmed it was valid motion and not just wind.
 
Last edited:
Upvote 0
Top