Reading notification without NotificationListenerService in android - android

I'm currently working on app that read certain notifications and then silencing some of them. I've managed doing this using NotificationListenerService on Android 4.3+ but I would like to make it compatible for previous versions too. So is there anyway to listening to incoming notifications and getting its content?
I heard about AccesibilityService but I don't quite understand if it is possible to use it to read notifications' content and how. Any suggestions?
Thanks from adavnce!

It's possible with the accessibility service (event 64)
You can get at the notification object from this and then parse it.
There's a sample class of parsing the notification here: http://notifications-widget.googlecode.com/svn/trunk/NotificationsWidget/src/com/roymam/android/notificationswidget/NotificationParser.java

Related

Handling Android Push notifications when app is not in the foreground using Delphi

My understanding is to receive the data from push notifications while the app is in the background or not running, one need a service which will put the data somewhere where the app can get at them when it starts up or goes to the foreground. It appears that a common solution is to put the data into the app's Extras.
There are plenty of references for Java but my google-fu fails to find an implementation guide for Delphi.
Also useful would be information on how to "Stack" the notifications into a single notification.
I imagine one could write a single service which is triggered each time a notification arrives, and which then a) puts the data portion of the notification into the app's extras, and b) replaces the notification with a single stacked notification.
My question is "how does one write this service" - some template code would help, and tutorials or reference documents would be great.
FWIW this is for an app with a chat like feature where one doesn't want any notifications to get lost.
One thing at a time... here's a guide for implementing a service on Android.
Full disclosure: I've no idea how effective or useful it is or how complete (or otherwise) Delphi capabilities for Android services are since I use Oxygene for Android development (also Object Pascal but works very differently than Delphi, enabling me to make use of all those Java references).
The rest of your question seems more related to specific business/application requirements than a programming/technical problem, but if you run into specific issues you should consider asking questions about those separately.

Read existing notifications on Android

How can I read existing notifications on Android? I want to be able to grab all the pending/existing notifications, parse them, and try to grab any information them. For instance, if my device had notifications from an SMS app, then I want to be able to read whatever information I could (if possible) from the notification. Is this possible?
Note that I am NOT asking for an active notification listener/receiver. I just want to be able to parse existing notifications on-demand.
Thanks in advance!
On devices with Android 4.3 and newer (API level 18) it is possible to use the NotificationListenerService and its function getActiveNotifications() to get a list of all outstanding notifications visible to the user. You can also react on each new notification by using onNotificationPosted.
On older devices, the only way to get access to the android notifications is to implement an AccessibilityService to react on incoming TYPE_NOTIFICATION_STATE_CHANGED-events.

Is it possible to suppress notifications in Android?

I'd like to be able to listen for notifications being sent to the status bar, and intercept and suppress (temporarily) those notifications.
I've seen AccessabilityEvent.TYPE_NOTIFICATION_STATE_CHANGED, and NotificationListenerService.
However, I just don't want to be informed when a notification is displayed, I want to prevent the notification from being displayed.
I can see how this could potentially be a security threat, so I can understand if it's not possible. Is this possible? If so, how would I go about doing it?
I think you're on the right track with the NotificationListenerService. Google has made these API's available from Android 4.3 on, so an application using this method would just be available for new devices.
In the following blogpost you can find an example of what you can do with the NotificationListenerService: http://weimenglee.blogspot.ch/2014/03/android-tip-notification-listener.html
The basic idea is to implement the onNotificationPosted() method, which gives you a StatusBarNotification instance. You should then be able to cancel the notification with this.cancelNotification(
notif.getPackageName(),
notif.getTag(),
notif.getId());
See the blogpost for a further description of what to extend and how to implement the methods.
Hope this helps.

I need to capture a notification

I need to know when a notification is created because I want to change the audio mode. Is possible?
Thank you very much.
With the release of Android 4.3 it is possible to get Notifications within a third-party app.
See NotificationListenerService for reference
You can use Notification class, However an answer on SO, suggests that
There is currently no generic way to intercept Notifications sent from other applications.
However if you want to listen something like SMS notifications than this link can be useful for you..

How can I discover and read active Android notifications?

How can I discover and read active Android notifications? If there is any way to launch them directly?
If you're referring to the standard Android notifications from the NotificationManager, then No, there is no way to discover and read active notifications. If you have access to the Android source code, you could modify the NotificationManagerService to provide this type of behavior.
If you're only concerned about duplicating notifications, the NotifcationManager has a built in system for preventing duplicate notifications.
As far as "launching them directly", I'm not entirely clear on what you're trying to do. What is it that you're trying to do that you can't accomplish using the functionality outlined here: http://developer.android.com/guide/topics/ui/notifiers/notifications.html?
I don't know what you want to find out. did you mean the notification with other apps? or cloud to device message?(C2DM). If you want catch the messages from google(C2DM) you can catch the messages with broadcastreciever in your application service. check the c2dm or notification service in google docs

Categories

Resources