Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Close Status Bar after Notification click

My notification contains several buttons :

  • 1 button launch back the main activity (should close status bar when doing so)
  • 4 of them send pending intents to control the music (should keep status bar open)

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

the 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));

the activity is correctly launched, but the status bar stays there and does not close itself.
Am I missing/misunderstanding a flag ? can I close the status bar progamaticaly from MyActivity.onResume() ?
edit: by the way, the notification is pushed by a service

thanks =)

like image 931
elgui Avatar asked Aug 21 '12 15:08

elgui


People also ask

How do I get rid of status bar on Samsung?

If you have a stock Android phone, you can remove the notification bar using System UI Tuner. For all other Android models, you can do this using a third-party app. In order for this to work, you must grant the app write secure settings permissions.

How do I change my status bar settings?

To customize it, first pull down the slider bar from the top of the screen. Next, tap on the three vertical dots in the top right corner. Now click on Status bar. You're in.

Why does my status bar keep disappearing?

This is caused by a Google™ bug, and may happen if your device fulfils the following: Software version Android™ 7.0 Nougat. Google Now™ is enabled.


4 Answers

You, just need to specify setAutoCancel(true) while creating builder. And that is all :)

NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_launcher)
            .setContentTitle("title goes here")
            .setContentText("content text goes here").setAutoCancel(true);
like image 87
rashadex Avatar answered Oct 02 '22 22:10

rashadex


Yeah, you'll have to cancel the notification programmatically when your app starts.

NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.cancel(NOTIFICATION_ID);
like image 27
devnate Avatar answered Oct 02 '22 22:10

devnate


ok, I found a solution... I could not reproduce the same behavior produced by standard notification, so I :
- made my imageButton "notif_album_IV" non clickable, and change it to an ImageView
- used this code :

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

instead of setting the setOnClickPendingIntent "manually" on the image, the intent broadcast is handled by the content background

like image 34
elgui Avatar answered Oct 02 '22 21:10

elgui


This worked for me:

sendBroadcast(new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS));
like image 44
Michael Litvin Avatar answered Oct 02 '22 20:10

Michael Litvin