Skip to content

Commit cfd4689

Browse files
tareksanderGrimler91
authored andcommitted
Added: channel selection to termux-notification, termux-notification-channel to create and delete channels.
1 parent 6f8a41e commit cfd4689

3 files changed

Lines changed: 46 additions & 1 deletion

File tree

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ set(script_files
3535
scripts/termux-microphone-record
3636
scripts/termux-nfc
3737
scripts/termux-notification
38+
scripts/termux-notification-channel
3839
scripts/termux-notification-list
3940
scripts/termux-notification-remove
4041
scripts/termux-sensor
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!@TERMUX_PREFIX@/bin/bash
2+
set -e -u
3+
4+
SCRIPTNAME=termux-notification-channel
5+
show_usage () {
6+
echo "Usage: $SCRIPTNAME -d channel-id"
7+
echo " $SCRIPTNAME channel-id channel-name"
8+
echo "Create or delete a notification channel."
9+
echo "Only usable on Android 8.0 and higher."
10+
echo "Use -d to delete a channel."
11+
echo "Creating a channel requires a channel id and a channel name."
12+
echo "The name will be visible in the options, the id is used to send notifications on that specific channel."
13+
echo "Creating a channel with the same id again will change the name."
14+
echo "Creating a channel with the same id as a deleted channel will restore the user settings of the deleted channel."
15+
echo "Use termux-notification --channel channel-id to send a notification on a custom channel."
16+
exit 0
17+
}
18+
19+
ARGS=""
20+
21+
if [ "$1" = "-d" ]; then
22+
shift
23+
if [ $# == 1 ]; then
24+
ARGS="--ez delete true --es id $1"
25+
else
26+
show_usage
27+
fi
28+
else
29+
if [ $# == 2 ]; then
30+
ARGS="--es id $1 --es name $2"
31+
else
32+
show_usage
33+
fi
34+
fi
35+
36+
37+
@TERMUX_PREFIX@/libexec/termux-api NotificationChannel $ARGS

scripts/termux-notification.in

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ show_usage () {
1717
echo " -c/--content content content to show in the notification. Will take"
1818
echo " precedence over stdin. If content is not passed as"
1919
echo " an argument or with stdin, then there will be a 3s delay."
20+
echo " --channel channel-id Specifies the notification channel id this notification should be send on."
21+
echo " On Android versions lower than 8.0 this is a no-op."
22+
echo " Create custom channels with termux-notification-channel."
23+
echo " If the channel id is invalid, the notification will not be send."
2024
echo " --group group notification group (notifications with the same"
2125
echo " group are shown together)"
2226
echo " -h/--help show this help"
@@ -88,6 +92,7 @@ OPT_BUTTON3_ACTION=""
8892
OPT_BUTTON3_TEXT=""
8993
OPT_CONTENT=""
9094
OPT_CONTENT_PASSED=""
95+
OPT_CHANNEL=""
9196
OPT_GROUP=""
9297
OPT_ID=""
9398
OPT_ICON=""
@@ -114,7 +119,7 @@ TEMP=`getopt \
114119
button1:,button1-action:,\
115120
button2:,button2-action:,\
116121
button3:,button3-action:,\
117-
content:,group:,help,help-actions,\
122+
content:,channel:,group:,help,help-actions,\
118123
id:,icon:,image-path:,\
119124
led-color:,led-on:,led-off:,\
120125
media-previous:,media-next:,media-play:,media-pause:,\
@@ -136,6 +141,7 @@ while true; do
136141
--button3) OPT_BUTTON3_TEXT="$2"; shift 2;;
137142
--button3-action) OPT_BUTTON3_ACTION="$2"; shift 2;;
138143
-c | --content) OPT_CONTENT_PASSED=1; OPT_CONTENT="$2"; shift 2;;
144+
--channel) OPT_CHANNEL="$2"; shift 2;;
139145
--group) OPT_GROUP="$2"; shift 2;;
140146
-h | --help) show_usage;;
141147
--help-actions) show_help_actions; exit 0;;
@@ -177,6 +183,7 @@ if [ -n "$OPT_BUTTON2_ACTION" ]; then set -- "$@" --es button_action_2 "$OPT_BUT
177183
if [ -n "$OPT_BUTTON2_TEXT" ]; then set -- "$@" --es button_text_2 "$OPT_BUTTON2_TEXT"; fi
178184
if [ -n "$OPT_BUTTON3_ACTION" ]; then set -- "$@" --es button_action_3 "$OPT_BUTTON3_ACTION"; fi
179185
if [ -n "$OPT_BUTTON3_TEXT" ]; then set -- "$@" --es button_text_3 "$OPT_BUTTON3_TEXT"; fi
186+
if [ -n "$OPT_CHANNEL" ]; then set -- "$@" --es channel "$OPT_CHANNEL"; fi
180187
if [ -n "$OPT_GROUP" ]; then set -- "$@" --es group "$OPT_GROUP"; fi
181188
if [ -n "$OPT_ID" ]; then set -- "$@" --es id "$OPT_ID"; fi
182189
if [ -n "$OPT_ICON" ]; then set -- "$@" --es icon "$OPT_ICON"; fi

0 commit comments

Comments
 (0)