How to prevent double click on android push notification action - notifications

I have two buttons on push notification.
If user fast clicking on them, the services (onHandleIntent) starts twice.
How to prevent it.
Intent.FLAG_ACTIVITY_SINGLE_TOP doesn't help.

Related

Disable local notifications on button press in Expo / react-native

I have an Expo app (which has been ejected but there is very little native code being used). I am using expo-notifications to schedule local notifications for the user. I am only doing this for background/killed state notifications. There are no foreground notifications.
I'd like to know if it's possible to turn them on or off when a button is pressed without losing all the notification data in React-native/Expo?
I want to add a toggle in the settings screen to turn notifications on or off and I can't figure out how to do this. I can of course cancel all scheduled notifications with cancelAllScheduledNotificationsAsync, but then if they toggle notifications back on all the existing ones would be lost.
I'm hoping to avoid having to store a bunch of data in AsyncStorage for this.
I'm working on handling this all in push notifications (which will solve a lot of headaches) but that's still a way out from being ready.

Show on Lock Screen push notification settings?

To get push notifications settings for an app I use:
[UIApplication sharedApplication].currentUserNotificationSettings
and then I check for the types of UIUserNotificationSettings. There are only 4 types None, Badge, Sound, Alert. If I use an app with settings like this:
I get that Sound, Badge, Alert is disabled and None is enabled. Why is None enabled if I still have “Show on Lock Screen” switch to ON? I am confused, is the “Show on Lock Screen” treated somehow different? From my understanding the app should still be able to receive push messages. Is there any way to find out “Show on Lock Screen” switch value for push notifications?
The API gives you access to the alert style when unlocked.
Given the fact that you still have the option Allow Notifications turned on, your app will still receive push notifications. So, by putting a breakpoint in code you'll see it being executed when you receive a push notification.
The currentUserNotificationSettings will tell you which type of alert style will be used for displaying when the phone is unlocked: None is a viable option and, along with Badge App Icon disabled your app can receive Push Notifications without showing any type of Banner, Alert, or Badge.
Show on Lock Screen can be seen as a way for the user to customize which notifications are and aren't presented, and in which way, in its phone. I don't think there's an API that will tell you whether or not that option is enabled.
I've just tested Messages.app with the exact same configuration you presented and by sending messages to myself there was no Badge, no Banner, no Alert but if I quickly lock the screen the phone wakes up with a notification in the Lock Screen.

Hide close button in a scheduled toast notification in Windows 10

Toast notification have a "close button" in the upper right corner.
Is there any way to either hide this button or to react to the user clicking it?
The use case is this: I want to reschedule a notification for the next day whenever a user reacts to the notification, even when closing it. In other words: the user cannot dismiss the notification forever.
The notification is scheduled from a background task which might not be running anymore when the notification is dismissed.
You can't hide it, or trigger an action when the 'x' icon clicked..
But, for your scenario, I'd suggest you to schedule the notification every day (or what ever your needs) and make it interactive notification (add a 'take action' button).. then if the user just dismissed it or closed it by whatever.. your Background Task is already running and your notifications are scheduled.. and the last option is to click on the take action, and then you can un schedule the notifications or stop the background task => your business logic :)

How to find out style of NSUserNotification during run-time? Or force close an alert?

According to OS X Mountain Lion Release Notes:
"The user has ultimate control over what notifications are displayed, and the style (banner, alert, etc). There is no mechanism to override the user preferences."
Even though all I want to do is "downgrade" from alert style to banner style... Fine. But can I at least find out whether a notification is of alert or banner style inside the didActivateNotification method?
When the alert is a banner (which is what I want), clicking its contents is the only possible action, and this both triggers didActivateNotification method with notification.activationType value of NSUserNotificationActivationTypeContentsClicked and closes the notification banner. I want my app to respond to this action by opening an internet URL.
When the user chooses alert-style notifications, clicking the alert contents also generates didActivateNotification with the same value of notification.activationType, but it stays on screen instead of going away (it only goes away when the Action button is pressed, and notification.activationType has a different value then). I don't want my app to trigger an action repeatedly for the same alert notification, in case the user clicks the content area of an alert notification.
An alternative solution would be to force the alert notification bubble to dismiss when the user clicks its contents. Is this possible?
You can remove the notification with the following:
[[NSUserNotificationCenter defaultUserNotificationCenter] removeDeliveredNotification:notification];

Send app to background on button tap

In my apps there is a button named "Back". When the user clicks on that button, the apps should be sent to the background, like when we click on the home button.
Even if you manage to do this, it is against Apple's HIG (because it will look as a crash to the user) - if you plan to publish your app on the AppStore you'll be rejected.
I think turning to background is impossible.
Make user press home button by using UIAlertView with no cancel button.
We can send an application to the background using SpringBoardUI or the SpringBoardServices private frameworks.
However, Apple won't accept this on the App Store.