Timelapse camera using droid script

235 views
Skip to first unread message

Rikaad Ytes

unread,
Sep 14, 2021, 6:16:44 PM9/14/21
to DroidScript
HI,
I have created a time lapse camera app using Android studio however i am not a great fan of Android Stdio and would like to create the App using Droidscript.

The App makes use of a broadcast receiver and a service to allow the activity to run in the background and also makes use of the alarm manager. Are there examples of using these concepts in droid script?

Any help is much appreciated.

Cheers.

Alan Hendry

unread,
Sep 15, 2021, 7:29:38 AM9/15/21
to DroidScript
Hi,
Droidscript can take photographs (and video)
Probably the best way to take a picture every few seconds/minutes/etc is a javascript interval
You can send your app to the background (and restart it)
You can add controls for the camera (time between photos, front/back camera, resolution, flash, etc).
To replay photos in a stream you could display an image and use an interval timer to change the image 

Dave

unread,
Sep 15, 2021, 8:41:04 AM9/15/21
to DroidScript
Yes, this is possible in DroidScript and I would recommend using the 'Background Service' template for Android versions below 10.  However you will face difficulties on Android 10 and higher as launching foreground apps from the background is blocked and background services are also severely restricted as to when they can run.

With new versions of Android you will probably need to 'pin' your app to the foreground and disable the lock screen.  Alternatively, if you can dedicated a device for the job, then enable full kiosk mode (COSU mode) using ADB, which will allow your app privileges to do almost anything.  See here for COSU info - https://androidscript.org/apk/DroidScript_209/X/ and see the docs for app.SetKioskMode for enabling and disabling that mode from code.

Setting your app as the system launcher might also allow you to get around some of the Android 10 restrictions (I've not tried that yet).

Dave

unread,
Sep 15, 2021, 8:52:45 AM9/15/21
to DroidScript

Rikaad Ytes

unread,
Sep 18, 2021, 3:05:06 AM9/18/21
to DroidScript
Hi,
And thanks for the replies/information, much appreciated.

Ideally what i would like to do is set up the time lapse camera so that it collects and stores an image then goes to sleep for a defined period of time, then wakes up and repeats this process, essentially in an effort to reduce battery use as image collection only occurs every 15 -20 minutes.

I had a look through the reference and found two functions App.GoToSleep() and app.WakeUp() which looked like it might be a good option however i read a post from 2018 that indicated that these two functions do not work on android versions after jelly bean. Is there an update to this or is this still the case?

Would adding a manifest file with the relevant permissions included make these functions work?

Would sending an App to the Background as suggested  above (and allowing phone to automatically switch off) and then reactivating it via an alarm have a similar effect to the sleep and wakeup functions? I will give this a go and see what happens.

Again, any helps with this is much appreciated.

Cheers.

Alan Hendry

unread,
Sep 18, 2021, 8:14:35 AM9/18/21
to DroidScript
HI,
I presume the user will set up the camera, and not use it for anything else ('til the exposures are done).
So (as Dave suggests) it would be worth looking at 
Kiosk Mode (not sure if it requires the X version, may prevent you putting your app on Google Play) or 
System Launcher (the Launcher under Samples seems to be Premium).
Other options are to use a charger or battery pack to extend the battery life.
You could try  to Stop() the camera and/or turn the screen black between shots, 
perhaps advise the user to turn off WiFi/Bluetooth.
Regards, ah

Rikaad Ytes

unread,
Sep 19, 2021, 6:02:55 AM9/19/21
to DroidScript


Hi,
And thanks for the reply.

Yes, camera will not be used for anything else.

Will check out Kiosk mode.

System currently uses an external battery pack that is charged from a solar panel and this setup works well however the ability to reduce power consumption by getting the app to go to sleep and then re-awake when required would be a significantly useful bonus as well as being useful in other areas not relate to image collection.

Currently the camera does stop in between collecting images and WiFi/Bluetooth is turned off but havent been able to get the screen to go black (turn off back-light) and keep app running. At least not using Android Studio anyway - might be easier to achieve using Droidscript?

I tried the suggestion by Dave to put App to the Background (and allowing phone to automatically switch off) and then reactivating it via an alarm - this partially worked. The activity (playing a sound) continued to operate in the background after phone automatically switched off screen but the alarm did not trigger untill i killed the App completely then it did trigger although i didnt understand what was going on here since i had killed the app using the stop button in Droid script.

Your helps with this is much appreciated.

Cheers.

Alan Hendry

unread,
Sep 19, 2021, 10:23:52 AM9/19/21
to DroidScript
Hi,
Android has now added a dark mode and one of the supposed advantages is lower battery usage.
In DS start and stop the camera as needed.
Also you could have the camera view with a black dialog, drawer, or frame on top of it.
Regards, ah

Dave

unread,
Sep 20, 2021, 7:47:24 AM9/20/21
to DroidScript
The most efficient way of saving power would be to use a device that supports power off and power on scheduling.   This way you could set the device to come on at a certain time each day and then turn off again after the photo has been taken if you want only one shot per day.  If you wan't more than one shot per day, then you could still turn off the device at night to save power for example.

I've seen some Huawei tablets that support this, so I expect there are some phones that support this too.  

Also on some device, you can set them to automatically turn on when they detect power on the USB cable.  This is an Android config setting that I have used in the past, but it seems a bit hit and miss depending on the device.   You will probably need a routed device for this or at least one that allows writing to the system folders.

Regards
David

Reply all
Reply to author
Forward
0 new messages