mirror of
https://github.com/fankes/termux-app.git
synced 2025-09-06 10:45:23 +08:00
Added!: Support for delete intent for Notification.Builder in NotificationUtils
This commit is contained in:
@@ -247,7 +247,7 @@ public class RunCommandService extends Service {
|
|||||||
Notification.Builder builder = NotificationUtils.geNotificationBuilder(this,
|
Notification.Builder builder = NotificationUtils.geNotificationBuilder(this,
|
||||||
TermuxConstants.TERMUX_RUN_COMMAND_NOTIFICATION_CHANNEL_ID, Notification.PRIORITY_LOW,
|
TermuxConstants.TERMUX_RUN_COMMAND_NOTIFICATION_CHANNEL_ID, Notification.PRIORITY_LOW,
|
||||||
TermuxConstants.TERMUX_RUN_COMMAND_NOTIFICATION_CHANNEL_NAME, null, null,
|
TermuxConstants.TERMUX_RUN_COMMAND_NOTIFICATION_CHANNEL_NAME, null, null,
|
||||||
null, NotificationUtils.NOTIFICATION_MODE_SILENT);
|
null, null, NotificationUtils.NOTIFICATION_MODE_SILENT);
|
||||||
if (builder == null) return null;
|
if (builder == null) return null;
|
||||||
|
|
||||||
// No need to show a timestamp:
|
// No need to show a timestamp:
|
||||||
|
@@ -708,7 +708,7 @@ public final class TermuxService extends Service implements TermuxTask.TermuxTas
|
|||||||
|
|
||||||
// Set pending intent to be launched when notification is clicked
|
// Set pending intent to be launched when notification is clicked
|
||||||
Intent notificationIntent = TermuxActivity.newInstance(this);
|
Intent notificationIntent = TermuxActivity.newInstance(this);
|
||||||
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
|
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
|
||||||
|
|
||||||
|
|
||||||
// Set notification text
|
// Set notification text
|
||||||
@@ -733,7 +733,7 @@ public final class TermuxService extends Service implements TermuxTask.TermuxTas
|
|||||||
Notification.Builder builder = NotificationUtils.geNotificationBuilder(this,
|
Notification.Builder builder = NotificationUtils.geNotificationBuilder(this,
|
||||||
TermuxConstants.TERMUX_APP_NOTIFICATION_CHANNEL_ID, priority,
|
TermuxConstants.TERMUX_APP_NOTIFICATION_CHANNEL_ID, priority,
|
||||||
getText(R.string.application_name), notificationText, null,
|
getText(R.string.application_name), notificationText, null,
|
||||||
pendingIntent, NotificationUtils.NOTIFICATION_MODE_SILENT);
|
contentIntent, null, NotificationUtils.NOTIFICATION_MODE_SILENT);
|
||||||
if (builder == null) return null;
|
if (builder == null) return null;
|
||||||
|
|
||||||
// No need to show a timestamp:
|
// No need to show a timestamp:
|
||||||
|
@@ -132,13 +132,15 @@ public class CrashUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Intent notificationIntent = ReportActivity.newInstance(context, new ReportInfo(UserAction.CRASH_REPORT.getName(), logTag, title, null, reportString.toString(), "\n\n" + TermuxUtils.getReportIssueMarkdownString(context), true));
|
Intent notificationIntent = ReportActivity.newInstance(context, new ReportInfo(UserAction.CRASH_REPORT.getName(), logTag, title, null, reportString.toString(), "\n\n" + TermuxUtils.getReportIssueMarkdownString(context), true));
|
||||||
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
|
PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
|
||||||
|
PendingIntent deleteIntent = null;
|
||||||
|
|
||||||
// Setup the notification channel if not already set up
|
// Setup the notification channel if not already set up
|
||||||
setupCrashReportsNotificationChannel(context);
|
setupCrashReportsNotificationChannel(context);
|
||||||
|
|
||||||
// Build the notification
|
// Build the notification
|
||||||
Notification.Builder builder = getCrashReportsNotificationBuilder(context, title, null, null, pendingIntent, NotificationUtils.NOTIFICATION_MODE_VIBRATE);
|
Notification.Builder builder = getCrashReportsNotificationBuilder(context, title, null,
|
||||||
|
null, contentIntent, deleteIntent, NotificationUtils.NOTIFICATION_MODE_VIBRATE);
|
||||||
if (builder == null) return;
|
if (builder == null) return;
|
||||||
|
|
||||||
// Send the notification
|
// Send the notification
|
||||||
@@ -156,16 +158,17 @@ public class CrashUtils {
|
|||||||
* @param title The title for the notification.
|
* @param title The title for the notification.
|
||||||
* @param notificationText The second line text of the notification.
|
* @param notificationText The second line text of the notification.
|
||||||
* @param notificationBigText The full text of the notification that may optionally be styled.
|
* @param notificationBigText The full text of the notification that may optionally be styled.
|
||||||
* @param pendingIntent The {@link PendingIntent} which should be sent when notification is clicked.
|
* @param contentIntent The {@link PendingIntent} which should be sent when notification is clicked.
|
||||||
|
* @param deleteIntent The {@link PendingIntent} which should be sent when notification is deleted.
|
||||||
* @param notificationMode The notification mode. It must be one of {@code NotificationUtils.NOTIFICATION_MODE_*}.
|
* @param notificationMode The notification mode. It must be one of {@code NotificationUtils.NOTIFICATION_MODE_*}.
|
||||||
* @return Returns the {@link Notification.Builder}.
|
* @return Returns the {@link Notification.Builder}.
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
public static Notification.Builder getCrashReportsNotificationBuilder(final Context context, final CharSequence title, final CharSequence notificationText, final CharSequence notificationBigText, final PendingIntent pendingIntent, final int notificationMode) {
|
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) {
|
||||||
|
|
||||||
Notification.Builder builder = NotificationUtils.geNotificationBuilder(context,
|
Notification.Builder builder = NotificationUtils.geNotificationBuilder(context,
|
||||||
TermuxConstants.TERMUX_CRASH_REPORTS_NOTIFICATION_CHANNEL_ID, Notification.PRIORITY_HIGH,
|
TermuxConstants.TERMUX_CRASH_REPORTS_NOTIFICATION_CHANNEL_ID, Notification.PRIORITY_HIGH,
|
||||||
title, notificationText, notificationBigText, pendingIntent, notificationMode);
|
title, notificationText, notificationBigText, contentIntent, deleteIntent, notificationMode);
|
||||||
|
|
||||||
if (builder == null) return null;
|
if (builder == null) return null;
|
||||||
|
|
||||||
|
@@ -220,7 +220,8 @@ public class PluginUtils {
|
|||||||
reportString.append("\n\n").append(AndroidUtils.getDeviceInfoMarkdownString(context));
|
reportString.append("\n\n").append(AndroidUtils.getDeviceInfoMarkdownString(context));
|
||||||
|
|
||||||
Intent notificationIntent = ReportActivity.newInstance(context, new ReportInfo(UserAction.PLUGIN_EXECUTION_COMMAND.getName(), logTag, title, null, reportString.toString(), null,true));
|
Intent notificationIntent = ReportActivity.newInstance(context, new ReportInfo(UserAction.PLUGIN_EXECUTION_COMMAND.getName(), logTag, title, null, reportString.toString(), null,true));
|
||||||
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
|
PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
|
||||||
|
PendingIntent deleteIntent = null;
|
||||||
|
|
||||||
// Setup the notification channel if not already set up
|
// Setup the notification channel if not already set up
|
||||||
setupPluginCommandErrorsNotificationChannel(context);
|
setupPluginCommandErrorsNotificationChannel(context);
|
||||||
@@ -230,7 +231,8 @@ public class PluginUtils {
|
|||||||
//CharSequence notificationTextCharSequence = notificationTextString;
|
//CharSequence notificationTextCharSequence = notificationTextString;
|
||||||
|
|
||||||
// Build the notification
|
// Build the notification
|
||||||
Notification.Builder builder = getPluginCommandErrorsNotificationBuilder(context, title, notificationTextCharSequence, notificationTextCharSequence, pendingIntent, NotificationUtils.NOTIFICATION_MODE_VIBRATE);
|
Notification.Builder builder = getPluginCommandErrorsNotificationBuilder(context, title,
|
||||||
|
notificationTextCharSequence, notificationTextCharSequence, contentIntent, deleteIntent, NotificationUtils.NOTIFICATION_MODE_VIBRATE);
|
||||||
if (builder == null) return;
|
if (builder == null) return;
|
||||||
|
|
||||||
// Send the notification
|
// Send the notification
|
||||||
@@ -248,16 +250,19 @@ public class PluginUtils {
|
|||||||
* @param title The title for the notification.
|
* @param title The title for the notification.
|
||||||
* @param notificationText The second line text of the notification.
|
* @param notificationText The second line text of the notification.
|
||||||
* @param notificationBigText The full text of the notification that may optionally be styled.
|
* @param notificationBigText The full text of the notification that may optionally be styled.
|
||||||
* @param pendingIntent The {@link PendingIntent} which should be sent when notification is clicked.
|
* @param contentIntent The {@link PendingIntent} which should be sent when notification is clicked.
|
||||||
|
* @param deleteIntent The {@link PendingIntent} which should be sent when notification is deleted.
|
||||||
* @param notificationMode The notification mode. It must be one of {@code NotificationUtils.NOTIFICATION_MODE_*}.
|
* @param notificationMode The notification mode. It must be one of {@code NotificationUtils.NOTIFICATION_MODE_*}.
|
||||||
* @return Returns the {@link Notification.Builder}.
|
* @return Returns the {@link Notification.Builder}.
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
public static Notification.Builder getPluginCommandErrorsNotificationBuilder(final Context context, final CharSequence title, final CharSequence notificationText, final CharSequence notificationBigText, final PendingIntent pendingIntent, final int notificationMode) {
|
public static Notification.Builder getPluginCommandErrorsNotificationBuilder(
|
||||||
|
final Context context, final CharSequence title, final CharSequence notificationText,
|
||||||
|
final CharSequence notificationBigText, final PendingIntent contentIntent, final PendingIntent deleteIntent, final int notificationMode) {
|
||||||
|
|
||||||
Notification.Builder builder = NotificationUtils.geNotificationBuilder(context,
|
Notification.Builder builder = NotificationUtils.geNotificationBuilder(context,
|
||||||
TermuxConstants.TERMUX_PLUGIN_COMMAND_ERRORS_NOTIFICATION_CHANNEL_ID, Notification.PRIORITY_HIGH,
|
TermuxConstants.TERMUX_PLUGIN_COMMAND_ERRORS_NOTIFICATION_CHANNEL_ID, Notification.PRIORITY_HIGH,
|
||||||
title, notificationText, notificationBigText, pendingIntent, notificationMode);
|
title, notificationText, notificationBigText, contentIntent, deleteIntent, notificationMode);
|
||||||
|
|
||||||
if (builder == null) return null;
|
if (builder == null) return null;
|
||||||
|
|
||||||
|
@@ -53,20 +53,25 @@ public class NotificationUtils {
|
|||||||
* @param title The title for the notification.
|
* @param title The title for the notification.
|
||||||
* @param notificationText The second line text of the notification.
|
* @param notificationText The second line text of the notification.
|
||||||
* @param notificationBigText The full text of the notification that may optionally be styled.
|
* @param notificationBigText The full text of the notification that may optionally be styled.
|
||||||
* @param pendingIntent The {@link PendingIntent} which should be sent when notification is clicked.
|
* @param contentIntent The {@link PendingIntent} which should be sent when notification is clicked.
|
||||||
|
* @param deleteIntent The {@link PendingIntent} which should be sent when notification is deleted.
|
||||||
* @param notificationMode The notification mode. It must be one of {@code NotificationUtils.NOTIFICATION_MODE_*}.
|
* @param notificationMode The notification mode. It must be one of {@code NotificationUtils.NOTIFICATION_MODE_*}.
|
||||||
* The builder returned will be {@code null} if {@link #NOTIFICATION_MODE_NONE}
|
* The builder returned will be {@code null} if {@link #NOTIFICATION_MODE_NONE}
|
||||||
* is passed. That case should ideally be handled before calling this function.
|
* is passed. That case should ideally be handled before calling this function.
|
||||||
* @return Returns the {@link Notification.Builder}.
|
* @return Returns the {@link Notification.Builder}.
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
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) {
|
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 contentIntent, final PendingIntent deleteIntent, final int notificationMode) {
|
||||||
if (context == null) return null;
|
if (context == null) return null;
|
||||||
Notification.Builder builder = new Notification.Builder(context);
|
Notification.Builder builder = new Notification.Builder(context);
|
||||||
builder.setContentTitle(title);
|
builder.setContentTitle(title);
|
||||||
builder.setContentText(notificationText);
|
builder.setContentText(notificationText);
|
||||||
builder.setStyle(new Notification.BigTextStyle().bigText(notificationBigText));
|
builder.setStyle(new Notification.BigTextStyle().bigText(notificationBigText));
|
||||||
builder.setContentIntent(pendingIntent);
|
builder.setContentIntent(contentIntent);
|
||||||
|
builder.setDeleteIntent(deleteIntent);
|
||||||
|
|
||||||
builder.setPriority(priority);
|
builder.setPriority(priority);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user