0

I have a notification that, when I click on it, opens up my app. But my app opens up in the background and the notification drawer is still visible. My notification itself is canceled and removed, but the drawer still exists on top of everything.

The notification class looks like this:

 public MyNotification(final Context context) {
    this.context = context;

    remoteView = new RemoteViews(context.getPackageName(), R.layout.notification);

    notification = new Builder(context)
            .setSmallIcon(R.drawable.notification_icon)
            .build();

    notification.flags = Notification.FLAG_NO_CLEAR;
    notification.priority = Notification.PRIORITY_MAX;

    remoteView.setOnClickPendingIntent(R.id.container, getIntent(ACTION_OPEN_APP));

    notification.bigContentView = remoteView;

    notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(MY_NOTIFICATION_ID, notification);
}

private PendingIntent getIntent(String action) {
    Intent receiveIntent = new Intent(context, NotificationReceiver.class);
    receiveIntent.setAction(action);
    return PendingIntent.getBroadcast(context, 0, receiveIntent, 0);
}

And my receiver looks like this:

public class NotificationReceiver extends BroadcastReceiver {

@Override
public void onReceive(Context context, Intent intent) {
    String action = intent.getAction();

    if(action.equalsIgnoreCase(AudioPlayerNotification.ACTION_OPEN_APP)) {

        Intent openAppIntent = new Intent(context, MyActivity.class);
        openAppIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
        context.startActivity(openAppIntent);
    }
}

App in the backtround with notification drawer on top

I also have a base Activity that removes the notification when launching the activity. What am I missing?

Cœur
  • 37,241
  • 25
  • 195
  • 267
peuhse
  • 1,688
  • 2
  • 20
  • 32

1 Answers1

0

Prathibhas suggested solution did not the trick, but pointed me in the right direction. The trick was to send the broadcast

sendBroadcast(new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS));

since I'm using a broadcast receiver for the actions on the notification. The answer was provided here:

Clicking Android Notification Actions does not close Notification drawer

Community
  • 1
  • 1
peuhse
  • 1,688
  • 2
  • 20
  • 32