termux-api: Updated package in termux-camera-photo
[termux-packages] / packages / termux-api / termux-camera-photo
CommitLineData
59f0d218
FF
1#!/system/bin/sh
2
3set -e -u
4
59f0d218 5show_usage () {
96015885 6 echo "usage: termux-camera-photo [OPTIONS] <output-file>"
59f0d218
FF
7 echo ""
8 echo "Take a photo and save it in a file. Valid options:"
96015885
FF
9 echo " -c, --camera <camera-id> the ID of the camera to use"
10 echo "Use termux-camera-info for information about available camera IDs."
59f0d218
FF
11}
12
13PARAM_CAMERA=""
14PARAM_SIZE=""
15O=`getopt -l camera: -l help -l size -- c:hs: "$@"`
16eval set -- "$O"
17while true; do
18case "$1" in
19 -c|--camera) PARAM_CAMERA="--ei camera $2"; shift 2;;
20 -h|--help) show_usage; exit 0;;
21 -s|--size) PARAM_SIZE="--ei size_index $2"; shift 2;;
22 --) shift; break;;
23 *) echo Error; exit 1;;
24esac
25done
26
27touch $1
28FILE=`realpath $1`
29
30# Output is like:
96015885 31# Broadcasting: Intent { cmp=com.termux.api/.PhotoActivity }
59f0d218 32# Broadcast completed: result=13, data="http://fornwall.net"
96015885 33OUTPUT=`am start --user 0 $PARAM_CAMERA $PARAM_SIZE --es file $FILE -n com.termux.api/.PhotoActivity | grep result=1 | cut -d ' ' -f 4`
59f0d218
FF
34
35if [ $? != "0" ]; then
96015885 36 echo "termux-camera-photo failed - see logs by executing 'adb logcat -s termux-api:*'"
59f0d218
FF
37 exit 1
38fi