7

Is there any Zenity alternative available for Android?

I am trying to do something like this using a Bash script in my Android device:

  1. Show a pop-up message
  2. Play a notification tone
  3. Show a pop-up window with text (or number) input box;
  4. Add item to notification panel;
  5. Show toaster message?

Is it possible to do this without using any external tool (or with only lightweight external tool)? If not then please name some command-line tools for this purpose.

Expected usage scenario, from command line:

$ ANWSER=$(android_show_message --buttons OK,Cancel "Do you really want ...?" )
 (android_show_message script brings up a tiny apk app using `am start`)
 (android_show_message communicates with the app to configure what it want to do)
 (android_show_message waits until the app tells it to exit)
 user presses "OK", android_show_message exits successfully, printing "OK";
$ if [ "$ANSWER" == "OK" ]; then android_show_message --toast "Operation completed"; fi
 (a toast message is shown)
1
  • It can be implemented as a pair of "apk" application that shows dialog and a script that manages connection to this apk (using sockets or sd card).
    – Vi.
    Commented Apr 13, 2015 at 9:19

2 Answers 2

1

Installing a command line tool will need a terminal app to be installed on your device. Instead you can use following third-party tools

Tasker can do these things for you.

Just a little heads-up. It is a paid app and a trial version is available. Please test it before you buy. It needs little advanced understanding.

There is also Trigger

Simple, free but has limited workings Let us know which one you choose.

12
  • 2
    How do I call from bash to Tasker/Trigger and read user's input back in bash?
    – Vi.
    Commented Apr 14, 2015 at 23:43
  • Also someting simple expected, but a complex thing that can be also misused as just a message/inputbox shower from remote.
    – Vi.
    Commented Apr 14, 2015 at 23:44
  • There is no exact alternative. but both apps can automate the tasks you needed. what you are trying to do exactly by taking input back to terminal? Commented Apr 16, 2015 at 2:42
  • To have interactive scripts that work on Linux also work on Android.
    – Vi.
    Commented Apr 16, 2015 at 10:44
  • 1
    For this there should be Python + something toolkit to support Zenity already on Android. This leads to heavy-weight solution. Also the way of communication between "command line world" and "Android GUI world" is not covered.
    – Vi.
    Commented Apr 19, 2015 at 12:35
0

This is doable with termux and the termux-api (apk) extension which exposes among other commands the termux-dialog:

confirm - Show confirmation dialog
    [-i hint] text hint (optional)
    [-t title] set title of dialog (optional)

checkbox - Select multiple values using checkboxes
    [-v ",,,"] comma delim values to use (required)
    [-t title] set title of dialog (optional)

counter - Pick a number in specified range
    [-r min,max,start] comma delim of (3) numbers to use (optional)
    [-t title] set title of dialog (optional)

date - Pick a date
    [-t title] set title of dialog (optional)
    [-d "dd-MM-yyyy k:m:s"] SimpleDateFormat Pattern for date widget output (optional)

radio - Pick a single value from radio buttons
    [-v ",,,"] comma delim values to use (required)
    [-t title] set title of dialog (optional)

sheet - Pick a value from sliding bottom sheet
    [-v ",,,"] comma delim values to use (required)
    [-t title] set title of dialog (optional)

spinner - Pick a single value from a dropdown spinner
    [-v ",,,"] comma delim values to use (required)
    [-t title] set title of dialog (optional)

speech - Obtain speech using device microphone
    [-i hint] text hint (optional)
    [-t title] set title of dialog (optional)

text - Input text (default if no widget specified)
    [-i hint] text hint (optional)
    [-m] multiple lines instead of single (optional)*
    [-n] enter input as numbers (optional)*
    [-p] enter input as password (optional)
    [-t title] set title of dialog (optional)
       * cannot use [-m] with [-n]

time - Pick a time value
    [-t title] set title of dialog (optional)

An example of a text input (text can be omitted as it's the default widget type):

termux-dialog text -t "Please enter a name"

The result is returned as json so you'd probably want to use something like jq to parse it.

name=$(termux-dialog text -t "Please enter a name" | jq '.text')

echo "$name"

If you put your scripts into the ~/.shortcuts folder then you can run them with a single tap via the Termux Widgets add-on.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.