0

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

Leo Chen
  • 969
  • 1
  • 11
  • 25
  • never tried googling? http://developer.android.com/design/patterns/settings.html – injecteer Apr 15 '15 at 09:57
  • hi, I did google but i can't find anywhere close. I'm looking for a piece of code that when executed, disables the notification coming from my app as well as update the setting. Is this possible? – Leo Chen Apr 15 '15 at 10:11

1 Answers1

0

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.

Community
  • 1
  • 1
Evripidis Drakos
  • 872
  • 1
  • 7
  • 15
  • That is one way, but then the state won't be consistent with the state in Settings -> Sound & notification -> App notification For example, user might have disabled the notification using your method, but then in settings it still shows as enabled.. – Leo Chen Apr 16 '15 at 02:54
  • of course, the option in settings will always have precedence over the preferences in an app, thats the whole point. The actual problem is that with no ui there no way to reenable the notification, so one better solution is to either make a simple ui screen for such options, or just make it so the button doesnt disable the notifications forever but just for a prefixed time (hour, day, depending on needs) – Evripidis Drakos Apr 16 '15 at 10:03