Allow user the choice to stop receiving Android notification - android

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.

Related

Cancel notification without using Notification Manager

I have an application in which it receives the notification when fired from Backend. Now what I want to achieve is that the notification should disappear after 2 minutes if user has not clicked on it (even if my app is killed or background). I know that this can be achieved by using the Notification manager's setTimeoutAfter() but that will work only if am making my custom notification using Notifcation Manger.But i want to dismiss the Notification generated by System after 2 minutes.
Any kind of suggestion or help will be welcomed.
It is not possible to do that. The default system notification builder is pretty bare bones and will not handle it. The best you can do is set a delivery timeout so if the device was off it won't get the notification once it expires.
See https://firebase.google.com/docs/cloud-messaging/concept-options#when_to_use_platform_specific_keys (only works on Android and Web)

Detecting Android Wear Notification Dismiss Events

The Android Wear OS has recently been updated to 5.0, which includes the feature to "recover" the most recently dismissed notification.
As a consequence, a notification's delete intent is only triggered after the user can no longer recover the intent (after another notification is dismissed, or the user swipes down and lets the 'dismiss' timeout expire).
I am attempting to display a notification, which gets updated fairly regularly until the user dismisses it. For this, I need to know immediately when the user has dismissed the notification (before the "recover" option has expired), so that I can stop updating the notification. If I attempt to update the notification once it has been dismissed, it will launch a new notification. In effect, the notification can't be dismissed as it will be recreated immediately.
So my question is: Has anyone discovered a way to detect immediately when the user dismisses a notification on an Android Wear device, before the option to recover the notification expires? I suspect if such a method exists, it should also be possible to detect when the user recovers the notification.
How about this?
Setting this flag will make it so the notification is automatically canceled when the user clicks it in the panel. The PendingIntent set with setDeleteIntent(PendingIntent) will be broadcast when the notification is canceled.
public NotificationCompat.Builder setAutoCancel (boolean autoCancel)
As I see it, it dismisses the notification immediately and it sends the setDeleteIntent() at the same time

I want open a dialog box containing message periodically to users of app

We want to send messages to app users either through notifications, dialog box or image opening up on their screen every 24 hours telling them that our app is running on their phone.
We were looking to use Notification builder but it has limitation that it only works for api 11 and above and half of all app installations today are for earlier api versions. We are trying to find out which would be the best way to go with this.
I'm not sure what "Notification builder" is, but you can certainly use Notification and NotificationManager in any API you want.
So, putting it all together, I would use AlarmManager to fire off an alarm every 24 hours. Set up this alarm when your application runs, and in a BroadcastReceiver which is configured to receive BOOT_COMPLETED. The BOOT_COMPLETED notification allows you to quietly restart the alarm if the device reboots.
The alarm triggers another BroadcastReceiver which puts the notification up. If the user selects the notification, then your application is launched. Mostly, the presence of the notification will be all the reminder your user will need.
My notes say that NotificationManager can pop a View up onto the screen, which could be a dialog. However, I think a simple icon in the status bar would be best, since you're just reminding the user that the application is present.
Oh, p.s., if your application is a service that's running in the background 24/7, then you should also remember to restart it in the BOOT_COMPLETED broadcast.

Android - DeleteIntent, how to use?

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.

Auto Notification for Android

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.

Categories

Resources