diff --git a/modules/react-native-status/android/src/main/java/im/status/ethereum/module/ForegroundService.java b/modules/react-native-status/android/src/main/java/im/status/ethereum/module/ForegroundService.java index 7b724bc0d4..914e7c25c8 100644 --- a/modules/react-native-status/android/src/main/java/im/status/ethereum/module/ForegroundService.java +++ b/modules/react-native-status/android/src/main/java/im/status/ethereum/module/ForegroundService.java @@ -52,6 +52,8 @@ public class ForegroundService extends Service { intent.setAction(Intent.ACTION_VIEW); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0); + Intent stopIntent = new Intent(NewMessageSignalHandler.ACTION_TAP_STOP); + PendingIntent stopPendingIntent = PendingIntent.getBroadcast(context, 0, stopIntent, PendingIntent.FLAG_CANCEL_CURRENT); String content = "Keep Status running to receive notifications"; Notification notification = new NotificationCompat.Builder(context, CHANNEL_ID) @@ -61,6 +63,7 @@ public class ForegroundService extends Service { .setPriority(NotificationCompat.PRIORITY_HIGH) .setCategory(NotificationCompat.CATEGORY_MESSAGE) .setContentIntent(pendingIntent) + .addAction(R.drawable.ic_stat_notify_status, "STOP", stopPendingIntent) .build(); // the id of the foreground notification MUST NOT be 0 startForeground(1, notification); diff --git a/modules/react-native-status/android/src/main/java/im/status/ethereum/module/NewMessageSignalHandler.java b/modules/react-native-status/android/src/main/java/im/status/ethereum/module/NewMessageSignalHandler.java index 5d2fe9d091..3265a7d444 100644 --- a/modules/react-native-status/android/src/main/java/im/status/ethereum/module/NewMessageSignalHandler.java +++ b/modules/react-native-status/android/src/main/java/im/status/ethereum/module/NewMessageSignalHandler.java @@ -46,6 +46,7 @@ public class NewMessageSignalHandler { //in notificationActionReceiver. public static final String ACTION_DELETE_NOTIFICATION = "im.status.ethereum.module.DELETE_NOTIFICATION"; public static final String ACTION_TAP_NOTIFICATION = "im.status.ethereum.module.TAP_NOTIFICATION"; + public static final String ACTION_TAP_STOP = "im.status.ethereum.module.TAP_STOP"; private static final String GROUP_STATUS_MESSAGES = "im.status.notifications.message"; private static final String CHANNEL_NAME = "Status"; private static final String CHANNEL_DESCRIPTION = "Get notifications on new messages and mentions"; @@ -65,15 +66,21 @@ public class NewMessageSignalHandler { private final BroadcastReceiver notificationActionReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { - String chatId = intent.getExtras().getString("im.status.ethereum.chatId"); - if (intent.getAction() == ACTION_TAP_NOTIFICATION) { - context.startActivity(getOpenAppIntent(chatId)); - } - removeChat(chatId); - // clean up the group notifications when there is no - // more unread chats - if (chats.size() == 0) { - notificationManager.cancelAll(); + if (intent.getAction() == ACTION_TAP_NOTIFICATION || + intent.getAction() == ACTION_DELETE_NOTIFICATION) { + String chatId = intent.getExtras().getString("im.status.ethereum.chatId"); + if (intent.getAction() == ACTION_TAP_NOTIFICATION) { + context.startActivity(getOpenAppIntent(chatId)); + } + removeChat(chatId); + // clean up the group notifications when there is no + // more unread chats + if (chats.size() == 0) { + notificationManager.cancelAll(); + }} + if (intent.getAction() == ACTION_TAP_STOP) { + stop(); + System.exit(0); } Log.e(TAG, "intent received: " + intent.getAction()); } @@ -83,6 +90,7 @@ public class NewMessageSignalHandler { IntentFilter filter = new IntentFilter(); filter.addAction(ACTION_DELETE_NOTIFICATION); filter.addAction(ACTION_TAP_NOTIFICATION); + filter.addAction(ACTION_TAP_STOP); context.registerReceiver(notificationActionReceiver, filter); Log.e(TAG, "Broadcast Receiver registered"); }