Trying to implement a snooze functionality on notification. (Correct me if I'm wrong) So I think one of the ways is to modify the alarm manager when the notification is triggered. So anyone knows if there is a method that's called when the notification is called? Thanks in advance.
So anyone knows if there is a method that's called when the notification is called?
I have no idea what you consider "the notification is called" to be.
You provide a PendingIntent to the Notification that will be invoked when the user taps on the Notification in the notification drawer. Usually, that PendingIntent will point to your code: activity, service, or BroadcastReceiver.
For Android 4.1 and higher, you can also have a "big" Notification style that has its own buttons, and you can tie a PendingIntent to each button.
Hence, on Android 4.1 and higher, I would expect "snooze" to be one of these action buttons, and you could use a broadcast PendingIntent to get control and make your changes to your alarm schedule. On Android 4.0 and earlier, "snooze" would be part of the activity that would come up when the user taps on the Notification, and you can adjust your alarm schedule at that point.
Related
In one of Activity-derived class methods I'm trying to send a Notification, clicking on which will bring the Activity to foreground if my app is in background (not visible) right now. There are reasons why I don't use Service, but use Activity (that will hold PARTIAL_WAKE_LOCK) for that.
I remember Notification worked for me when I used it like this, but I sent it from Service. Now when I send it from Activity method and it doesn't show up, though I hear its notification sound.
So are there any reasons that prevent Notification show up sent from Activity method and how can it be solved?
Thank you.
I was not exactly precise copying Notification code sample. I removed setSmallIcon() call from code as I was too lazy to add icons. As a result system was really dropping my Intent, saying that no icon is provided for it and it'll be a crash in future releases.
I wrote an app for Android L only that listens to USB connection using Broadcast Receiver.
This receiver fires a notification every time onReceive is called.
I think user would find it annoying so I would like to give user a chance of disabling it. I know in Android L user can disable this in Settings -> Sound & notification -> App notification but I would like to add this function on my notification itself.
So my question is, is it possible to add a checkbox on the notification and when checked, disables this notification with the App notification settings gets updated?
thanks
From android 4.1 and up you can use .addAction(R.drawable.icon, "Name", pendingIntent) on your Notification.Builder to add a button on the notification. This will launch the pending intent that you specified. There you can save a boolean value on sharedPreferences to enable or not the notifications which you will check before starting the notifications.
If you dont have any kind of ui and only need to call a service from the button, check here on how to achieve this.
I'm interested to know when a user cancels a Notification from by application - is this possible? I'd like to listen for the event and then stop a service that runs in the background.
There is not any way to see if notification was deleted by user. You can make notification "persistent" - it can't be cleared - and start some action when user clicks on it.
You know that we append a PendingIntent in notification, so by using that intent we can launch an activity which may close the service and then call finish() on itself to go away. The entire process might be fast enough that a user may not notice any hiccup
You can set a PendingIntent sent when the notification is cleared explicitly by the user.
Please, take a look over here: Notification.Builder setDeleteIntent (PendingIntent intent)
I currently have a notification in my Android application that has a PendingIntent so that when it is clicked an activity is opened.
I currently keep a counter for the notification, similar to the native missed calls notification.
I can reset this counter to 0 when the notification is clicked.
I also want to reset the counter to 0 when the user selects the "Clear all notifications" button. I have done a search and seen the way to do this is to use the DeleteIntent.
But I cant figure out how to use this alongside my PendingIntent, can anyone help me out?
Create a broadcast or service PendingIntent, pointing to a BroadcastReceiver or IntentService that will reset your counter, and associate that PendingIntent with your Notification via deleteIntent.
I'm new with Android programming. I'm just wondering whether its possible to set up auto notification. For example, every morning at 8am, the app will send a notification to user about something. Is this possible? Which area/class of Android programming should I look at? Thanks!
You should have a look at the Alarm Manager. You will need to use either of the 'set' methods, and give it a PendingIntent that will perform a broadcast or start an intent service that wakes up just to show the notification. For the broadcast, you will need to have a receiver in your app, that makes a Notification and shows it.