Commit | Line | Data |
---|---|---|
59f0d218 FF |
1 | #!/system/bin/sh |
2 | ||
3 | set -e -u | |
4 | ||
59f0d218 | 5 | show_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 | ||
13 | PARAM_CAMERA="" | |
14 | PARAM_SIZE="" | |
15 | O=`getopt -l camera: -l help -l size -- c:hs: "$@"` | |
16 | eval set -- "$O" | |
17 | while true; do | |
18 | case "$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;; | |
24 | esac | |
25 | done | |
26 | ||
27 | touch $1 | |
28 | FILE=`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 | 33 | OUTPUT=`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 | |
35 | if [ $? != "0" ]; then | |
96015885 | 36 | echo "termux-camera-photo failed - see logs by executing 'adb logcat -s termux-api:*'" |
59f0d218 FF |
37 | exit 1 |
38 | fi |