这是indexloc提供的服务,不要输入任何密码
Skip to content

Commit baacabd

Browse files
Added!: Support for delete intent for Notification.Builder in NotificationUtils
1 parent 35ea19d commit baacabd

File tree

5 files changed

+29
-16
lines changed

5 files changed

+29
-16
lines changed

app/src/main/java/com/termux/app/RunCommandService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ private Notification buildNotification() {
247247
Notification.Builder builder = NotificationUtils.geNotificationBuilder(this,
248248
TermuxConstants.TERMUX_RUN_COMMAND_NOTIFICATION_CHANNEL_ID, Notification.PRIORITY_LOW,
249249
TermuxConstants.TERMUX_RUN_COMMAND_NOTIFICATION_CHANNEL_NAME, null, null,
250-
null, NotificationUtils.NOTIFICATION_MODE_SILENT);
250+
null, null, NotificationUtils.NOTIFICATION_MODE_SILENT);
251251
if (builder == null) return null;
252252

253253
// No need to show a timestamp:

app/src/main/java/com/termux/app/TermuxService.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -708,7 +708,7 @@ private Notification buildNotification() {
708708

709709
// Set pending intent to be launched when notification is clicked
710710
Intent notificationIntent = TermuxActivity.newInstance(this);
711-
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
711+
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
712712

713713

714714
// Set notification text
@@ -733,7 +733,7 @@ private Notification buildNotification() {
733733
Notification.Builder builder = NotificationUtils.geNotificationBuilder(this,
734734
TermuxConstants.TERMUX_APP_NOTIFICATION_CHANNEL_ID, priority,
735735
getText(R.string.application_name), notificationText, null,
736-
pendingIntent, NotificationUtils.NOTIFICATION_MODE_SILENT);
736+
contentIntent, null, NotificationUtils.NOTIFICATION_MODE_SILENT);
737737
if (builder == null) return null;
738738

739739
// No need to show a timestamp:

app/src/main/java/com/termux/app/utils/CrashUtils.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -132,13 +132,15 @@ public static void sendCrashReportNotification(final Context context, String log
132132
}
133133

134134
Intent notificationIntent = ReportActivity.newInstance(context, new ReportInfo(UserAction.CRASH_REPORT.getName(), logTag, title, null, reportString.toString(), "\n\n" + TermuxUtils.getReportIssueMarkdownString(context), true));
135-
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
135+
PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
136+
PendingIntent deleteIntent = null;
136137

137138
// Setup the notification channel if not already set up
138139
setupCrashReportsNotificationChannel(context);
139140

140141
// Build the notification
141-
Notification.Builder builder = getCrashReportsNotificationBuilder(context, title, null, null, pendingIntent, NotificationUtils.NOTIFICATION_MODE_VIBRATE);
142+
Notification.Builder builder = getCrashReportsNotificationBuilder(context, title, null,
143+
null, contentIntent, deleteIntent, NotificationUtils.NOTIFICATION_MODE_VIBRATE);
142144
if (builder == null) return;
143145

144146
// Send the notification
@@ -156,16 +158,17 @@ public static void sendCrashReportNotification(final Context context, String log
156158
* @param title The title for the notification.
157159
* @param notificationText The second line text of the notification.
158160
* @param notificationBigText The full text of the notification that may optionally be styled.
159-
* @param pendingIntent The {@link PendingIntent} which should be sent when notification is clicked.
161+
* @param contentIntent The {@link PendingIntent} which should be sent when notification is clicked.
162+
* @param deleteIntent The {@link PendingIntent} which should be sent when notification is deleted.
160163
* @param notificationMode The notification mode. It must be one of {@code NotificationUtils.NOTIFICATION_MODE_*}.
161164
* @return Returns the {@link Notification.Builder}.
162165
*/
163166
@Nullable
164-
public static Notification.Builder getCrashReportsNotificationBuilder(final Context context, final CharSequence title, final CharSequence notificationText, final CharSequence notificationBigText, final PendingIntent pendingIntent, final int notificationMode) {
167+
public static Notification.Builder getCrashReportsNotificationBuilder(final Context context, final CharSequence title, final CharSequence notificationText, final CharSequence notificationBigText, final PendingIntent contentIntent, final PendingIntent deleteIntent, final int notificationMode) {
165168

166169
Notification.Builder builder = NotificationUtils.geNotificationBuilder(context,
167170
TermuxConstants.TERMUX_CRASH_REPORTS_NOTIFICATION_CHANNEL_ID, Notification.PRIORITY_HIGH,
168-
title, notificationText, notificationBigText, pendingIntent, notificationMode);
171+
title, notificationText, notificationBigText, contentIntent, deleteIntent, notificationMode);
169172

170173
if (builder == null) return null;
171174

app/src/main/java/com/termux/app/utils/PluginUtils.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,8 @@ public static void sendPluginCommandErrorNotification(Context context, String lo
220220
reportString.append("\n\n").append(AndroidUtils.getDeviceInfoMarkdownString(context));
221221

222222
Intent notificationIntent = ReportActivity.newInstance(context, new ReportInfo(UserAction.PLUGIN_EXECUTION_COMMAND.getName(), logTag, title, null, reportString.toString(), null,true));
223-
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
223+
PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
224+
PendingIntent deleteIntent = null;
224225

225226
// Setup the notification channel if not already set up
226227
setupPluginCommandErrorsNotificationChannel(context);
@@ -230,7 +231,8 @@ public static void sendPluginCommandErrorNotification(Context context, String lo
230231
//CharSequence notificationTextCharSequence = notificationTextString;
231232

232233
// Build the notification
233-
Notification.Builder builder = getPluginCommandErrorsNotificationBuilder(context, title, notificationTextCharSequence, notificationTextCharSequence, pendingIntent, NotificationUtils.NOTIFICATION_MODE_VIBRATE);
234+
Notification.Builder builder = getPluginCommandErrorsNotificationBuilder(context, title,
235+
notificationTextCharSequence, notificationTextCharSequence, contentIntent, deleteIntent, NotificationUtils.NOTIFICATION_MODE_VIBRATE);
234236
if (builder == null) return;
235237

236238
// Send the notification
@@ -248,16 +250,19 @@ public static void sendPluginCommandErrorNotification(Context context, String lo
248250
* @param title The title for the notification.
249251
* @param notificationText The second line text of the notification.
250252
* @param notificationBigText The full text of the notification that may optionally be styled.
251-
* @param pendingIntent The {@link PendingIntent} which should be sent when notification is clicked.
253+
* @param contentIntent The {@link PendingIntent} which should be sent when notification is clicked.
254+
* @param deleteIntent The {@link PendingIntent} which should be sent when notification is deleted.
252255
* @param notificationMode The notification mode. It must be one of {@code NotificationUtils.NOTIFICATION_MODE_*}.
253256
* @return Returns the {@link Notification.Builder}.
254257
*/
255258
@Nullable
256-
public static Notification.Builder getPluginCommandErrorsNotificationBuilder(final Context context, final CharSequence title, final CharSequence notificationText, final CharSequence notificationBigText, final PendingIntent pendingIntent, final int notificationMode) {
259+
public static Notification.Builder getPluginCommandErrorsNotificationBuilder(
260+
final Context context, final CharSequence title, final CharSequence notificationText,
261+
final CharSequence notificationBigText, final PendingIntent contentIntent, final PendingIntent deleteIntent, final int notificationMode) {
257262

258263
Notification.Builder builder = NotificationUtils.geNotificationBuilder(context,
259264
TermuxConstants.TERMUX_PLUGIN_COMMAND_ERRORS_NOTIFICATION_CHANNEL_ID, Notification.PRIORITY_HIGH,
260-
title, notificationText, notificationBigText, pendingIntent, notificationMode);
265+
title, notificationText, notificationBigText, contentIntent, deleteIntent, notificationMode);
261266

262267
if (builder == null) return null;
263268

termux-shared/src/main/java/com/termux/shared/notification/NotificationUtils.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,20 +53,25 @@ public static NotificationManager getNotificationManager(final Context context)
5353
* @param title The title for the notification.
5454
* @param notificationText The second line text of the notification.
5555
* @param notificationBigText The full text of the notification that may optionally be styled.
56-
* @param pendingIntent The {@link PendingIntent} which should be sent when notification is clicked.
56+
* @param contentIntent The {@link PendingIntent} which should be sent when notification is clicked.
57+
* @param deleteIntent The {@link PendingIntent} which should be sent when notification is deleted.
5758
* @param notificationMode The notification mode. It must be one of {@code NotificationUtils.NOTIFICATION_MODE_*}.
5859
* The builder returned will be {@code null} if {@link #NOTIFICATION_MODE_NONE}
5960
* is passed. That case should ideally be handled before calling this function.
6061
* @return Returns the {@link Notification.Builder}.
6162
*/
6263
@Nullable
63-
public static Notification.Builder geNotificationBuilder(final Context context, final String channelId, final int priority, final CharSequence title, final CharSequence notificationText, final CharSequence notificationBigText, final PendingIntent pendingIntent, final int notificationMode) {
64+
public static Notification.Builder geNotificationBuilder(
65+
final Context context, final String channelId, final int priority, final CharSequence title,
66+
final CharSequence notificationText, final CharSequence notificationBigText,
67+
final PendingIntent contentIntent, final PendingIntent deleteIntent, final int notificationMode) {
6468
if (context == null) return null;
6569
Notification.Builder builder = new Notification.Builder(context);
6670
builder.setContentTitle(title);
6771
builder.setContentText(notificationText);
6872
builder.setStyle(new Notification.BigTextStyle().bigText(notificationBigText));
69-
builder.setContentIntent(pendingIntent);
73+
builder.setContentIntent(contentIntent);
74+
builder.setDeleteIntent(deleteIntent);
7075

7176
builder.setPriority(priority);
7277

0 commit comments

Comments
 (0)