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
Deep Linking Not Working in Chrome
Floatingactionbutton Doesn't Hide
How to Get the Dreaded Write_Secure_Settings Permission for My Android App
How to Apply Plugin to Only One Flavor in Gradle
Picasso Load Drawable Resources from Their Uri
How to Finish Activity When Starting Other Activity in Android
How to Get Information About Android Battery Usage by Application
Query the Google Play Store for the Version of an App
Android Sp VS Dp Texts - What Would Adjust the 'Scale' and What Is the Philosophy of Support
How to Fill Color in Image in Particular Area
How to Disable Dates Before Today Date in Datepickerdialog Android
How to Use Default Android Drawables
Genymotion Error After Windows 10 Upgrade
Syncing Android Studio Project with Gradle Files