Close status bar after notification

My notification contains several buttons:

  • 1 button launches the main action (when closing the status bar at the same time)
  • 4 of them send pending intentions to control the music (should open the status bar)

The problem is that the first button does not close the status bar ...

PendingIntent sent by the first button:

Intent activityIntent = new Intent(smp, MusicShaker.class)
            .setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
                    | Intent.FLAG_ACTIVITY_SINGLE_TOP);
activityIntent.setAction(MyIntentAction.DO_LAUNCH_ACTIVITY_FROM_NOTIF);
remoteViews.setOnClickPendingIntent(R.id.notif_album_IV, PendingIntent
            .getActivity(ctxt, 0, activityIntent,
                    PendingIntent.FLAG_CANCEL_CURRENT));

activity starts correctly, but the status bar remains there and does not close.
I do not see / underestimate the flag? Can I close the status bar in the program from MyActivity.onResume ()?
editing: by the way, the notification is pressed by the service

thanks =)

+5
source share
3 answers

ok, ... , , :
 - imageButton "notif_album_IV" ImageView
 - :

builder.setContentIntent(PendingIntent.getActivity(smp, 0,
  activityIntent,PendingIntent.FLAG_CANCEL_CURRENT))

, setOnClickPendingIntent "" ,

+2

setAutoCancel (true) . :)

NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_launcher)
            .setContentTitle("title goes here")
            .setContentText("content text goes here").setAutoCancel(true);
+3

Yes, you will need to cancel the notification programmatically when your application starts.

NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.cancel(NOTIFICATION_ID);
+1
source

All Articles