mirror of
https://github.com/status-im/status-react.git
synced 2025-01-22 00:41:07 +00:00
stop app when pressing stop button on notifications
This commit is contained in:
parent
fd874c14df
commit
51198f5b69
@ -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);
|
||||
|
@ -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");
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user