2

I want to add a mark as read option to the pull down notification bar of Gmail but I don't have the slightest clue about where to start. If somebody can tell me how to do it or point me in the direction of the right docs to pull it off it would be much appreciated.

I know it is possible because it has already been done, but I want to do it by myself.

Regent
  • 5,142
  • 3
  • 21
  • 35
Pombal
  • 23
  • 4
  • What do you mean by "the pull down notification bar of gmail"? – Mark Buikema Jul 28 '14 at 11:28
  • When you receive an email you get a gmail notification. If you pull that notification down you can see the Archive and Reply options. I want to add a Mark as Read option there but don't know how to program it. – Pombal Jul 28 '14 at 13:08

2 Answers2

2

That's quite an undertaking.

So the link you provided has a bit of a walkthrough in its description about where to start. The trick is that because you're trying to program a notification service for an EXISTING app, you don't really have control over the notifications the app itself creates. I suspect what you're going to have to do is program a NotificationListenerService, listen for gmail notifications, and somehow cancel the gmail notification and replace it with one of your own, as created through the android documentation.

For a good example of how NotificationListenerService works please take a look at this:

https://github.com/kpbird/NotificationListenerService-Example

The canceling is something I have not tested but you asked for ideas, not code. NotificationListenerService has a method cancelNotification(String pkg, String tag, int id) which looks like you can use to cancel the gmail notification.

Otra
  • 8,108
  • 3
  • 34
  • 49
  • even if you managed to cancel the existing notification and construct another - you wouldn't have access to any of the information displayed in the original right? Without building an email client yourself that the user has to enter their Gmail credentials into? – ataulm Jul 30 '14 at 15:19
  • You're possibly right about having to register the email. I wonder if the user could simply clone the notification, however, as you could use the StatusBarNotification supplied by "onNotificationPosted", and then use `sbn.getNotification().clone()` and modify the notification's layout. However the user wasn't very specific about coding, just where to get started. – Otra Jul 30 '14 at 15:28
  • So your idea is to cancel the gmail notification and build my own which would mimic the gmail one, but with the alteration I want, correct? I find it odd that you can cancel a notification that does not belong to your app... About the information the app would have access to, I believe the "ACCOUNTS & USE CREDENTIALS" permission would give me that access, as stated in the link I provided. – Pombal Jul 30 '14 at 16:25
  • I just tried it, and yes you can cancel the notification that does not belong to you. I mean you're asking to modify the notification, which seems more invasive than just canceling it. :) Anyway that method does work if you provide it the right parameters. – Otra Jul 30 '14 at 16:31
  • It is more invasive, that's I was sceptical that it would even be possible :) Thanks a lot, sounds like the best (only?) way to do it, except for Google actually adding a mark as read option, of course -_- – Pombal Jul 30 '14 at 16:38
  • Well good luck, this'll get you as far as making your own notification, but I suspect the next hurdle will be figuring out how to actually send a "email read" intent to gmail. – Otra Jul 30 '14 at 16:46
  • Thanks, I'm an Android noob so it seems this is a bit more than I can chew atm. I thought this would be a good idea to get me started since it is something I actually need.. Oh well, I'll try it anyway, gotta start somewhere ;) – Pombal Jul 30 '14 at 17:00
0

You can get access to the raw Notification-object using an AccessibilityService. I haven't tried it before to be honest, but I assume you can modify the Notification and add your own buttons, etc.

More information on tinkering with the Notification-object in an AccessibilityService here: https://stackoverflow.com/a/10303676/198996

Community
  • 1
  • 1
TomTasche
  • 5,448
  • 7
  • 41
  • 67