I have used this FLAG for my service : Notification.FLAG_FOREGROUND_SERVICE; but when I call notificationManager.cancel(IDN) the icon is always visual into the status bar.....if I change FLAG on Notification.FLAG_AUTO_CANCEL when I call notificationManager.cancel(IDN) the icon is gone. How can I do for to use FLAG_FOREGROUND_SERVICE and then cancel the icon ?
I'm not sure I got your question, but you can cancel all the notification from your App using:
final NotificationManager mNotificationManager = (NotificationManager) ctx.getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.cancelAll();
I used:
public final void startForeground (int id, Notification notification)
and the notification could be cancelled.
please refer this, for foreground service
Bit to be bitwise-ored into the flags field that should be set if this notification represents a currently running service. This will normally be set for you by startForeground(int, Notification)."
To help other people who might struggle with this, it would really help if the documentation for FLAG_FOREGORUND_SERVICE more strongly indicated that users of this flag can't use nm.cancel() and need to use the startForeground/stopForeground pair. Perhaps something like:
"Bit to be bitwise-ored into the flags field to indicate foreground status of a currently running service. You should not use this flag directly, but let startForeground() set it for you, and use stopForeground(true) to remove it."
Related
According to https://code.visualstudio.com/updates/v1_36#_hide-individual-status-bar-items we can now enable users to turn status bar messages on/off, but it doesn't point to a particular API to handle that ourselves.
I have looked at https://github.com/Microsoft/vscode-extension-samples/tree/master/statusbar-sample but it doesn't seem to show a method of handling that.
Is there a good example somewhere we can refer to?
I have not tried this myself, but going by the API docs, when you use window.createStatusBarItem you get back a StatusBarItem, which has a "hide" method. So calling that method seems like the first thing to try.
To understand NSUserNotification better, I wrote a little test app playing with this class.
So far so good, except that no matter how hard I tried to feed the additionalActions property with array of NSUserNotificationAction objects, it never showed any difference but only one action button and a close one.
My expectation for this property is that the notification would show a pull-down menu containing the additional buttons I offer as it does in the Mac App Store update notifications.
Am I missing something? Or are you having the same problem, since it is a bug awaiting Apple to tackle?
Can you please try to click and hold down the action button in your notification? Does it show a drop-down menu of additionalActions?
Update
As it turns out, you can show the little chevron next to the action button by setting a true value for the private _alwaysShowAlternateActionMenu key on the notification. In Swift 3, it would look like this:
notification.setValue(true, forKey: "_alwaysShowAlternateActionMenu")
However, as I mentioned this is a private API and I strongly advise against using it if you want to distribute your App through the Mac App Store.
It is probably a bug. Setting up additionalActions will create the list, but not the little arrow icon. Holding down on actionButton will show the menu with the number of actions you set.
Besides setting additionalActions will cause several other problems. I will save this for another question.
Refer to another question.
show NSUserNotification additionalActions on click
P.S. I am using El Capitan APIs
I am detecting whether the user has accepted the request to use location services in my app, I have a toggle switch in the UI that is dependent on this acceptance. The first time they toggle the switch (on) the request to use location is triggered. I want to know which button they press in that alert. (accept or decline) Right now I'm just toggling it off and making the user press it again (then detect which option they picked).
It is kind of sloppy that way, so I'd like to know if there is a way to detect this specific alert or can't that be done since it is triggered by the OS, not the application? I haven't tried it yet, but was thinking I could use the UIAlertView delegate methods for just generic button presses, but was hoping for something more specific.
UPDATE
I was able to get this working by just registering a notification when I trigger the location request (and the authorization prompt is shown). The application is placed in an inactive state (much like pulling down the notification bar). I just trigger a notification when the application becomes active and I'm able to just query the authorization status there and update my UI. I hope this helps anyone else down the line if they want to handle the authorization status on the fly.
There is no way to intercept the alert. There is, however, a method on CLLocationManagerDelegate method called didChangeAuthorizationStatus. That's probably the closest you can get to intercepting the alert.
There is no way to know explicitly which button the user selects since, as you've said, this alert comes from the OS. You can however, find out if location services has been enabled for your app, and know that way. Use a method such as this:
-(BOOL)locationServicesIsEnabled
{
if (![CLLocationManager locationServicesEnabled] || ![CLLocationManager authorizationStatus])
return NO;
return YES;
}
Is there any standard step by step way to use the local notification in iPhone application.
I have never worked for local notification.
I am interested to use this to create a fake call.
So, i am interested to set the timer in the local notification & as per the timer i have to set the local notification with custom view instead of the default pop up of notification.
Please suggest me the standard way to deal with local notification.
Every type of suggestions & links are appreciable in advance.
Thanks.
You can't customize the local notification alert. I have also once searched for this. Alternatively I ended with showing the custom alert when the user accepts the local notification (similar to 2Do:Task done in style application).
The NetBeans API provides the org.openide.awt.NotificationDisplayer class to create and show clickable notifications in the main status line. For example,
NotificationDisplayer.notify(title, icon, detailsText, detailsAction);
The user can dismiss a notification by clicking on the X; however, I would like to programmatically clear the notifications. How can I accomplish this?
The solution I end up with was to maintain a reference to the Notification object returned by the NotificationDisplayer.notify() method. The object provides a clear() method to force removal from the status line.