How to Close the Status Bar/Notification Panel After Notification Button Click

How to close the status bar/notification panel after notification button click

Ok I've found the solution. It's not public API, but it works (for the moment):

Object sbservice = c.getSystemService( "statusbar" );
Class<?> statusbarManager = Class.forName( "android.app.StatusBarManager" );
Method hidesb = statusbarManager.getMethod( "collapse" );
hidesb.invoke( sbservice );

For this to work

<uses-permission android:name="android.permission.EXPAND_STATUS_BAR"/>

is needed

Close Status Bar after Notification click

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

Close status bar when button notification is clicked

Ok, I solved it.

private int currentApiVersion = android.os.Build.VERSION.SDK_INT;
...

Object sbservice = context.getSystemService("statusbar");
try {
Class<?> statusbarManager = Class.forName("android.app.StatusBarManager");
if (currentApiVersion <= 16) {
Method collapse = statusbarManager.getMethod("collapse");
collapse.invoke(sbservice);
} else {
Method collapse2 = statusbarManager.getMethod("collapsePanels");
collapse2.invoke(sbservice);
}
} catch (Exception e) {
e.printStackTrace();
}

Android: remove notification from notification bar

This is quite simple. You have to call cancel or cancelAll on your NotificationManager. The parameter of the cancel method is the ID of the notification that should be canceled.

See the API: http://developer.android.com/reference/android/app/NotificationManager.html#cancel(int)



Related Topics



Leave a reply



Submit