| 1 | #!/system/bin/sh |
| 2 | |
| 3 | set -e -u |
| 4 | |
| 5 | show_usage () { |
| 6 | echo "usage: termux-camera-photo [OPTIONS] <output-file>" |
| 7 | echo "" |
| 8 | echo "Take a photo and save it in a file. Valid options:" |
| 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." |
| 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: |
| 31 | # Broadcasting: Intent { cmp=com.termux.api/.PhotoActivity } |
| 32 | # Broadcast completed: result=13, data="http://fornwall.net" |
| 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` |
| 34 | |
| 35 | if [ $? != "0" ]; then |
| 36 | echo "termux-camera-photo failed - see logs by executing 'adb logcat -s termux-api:*'" |
| 37 | exit 1 |
| 38 | fi |