How to get all notification of all application have custom notification running - android

I'm a beginner. I have a problem about custom notification.
I want to read all information of normal notification and custom notification use RemoteView.
Example I want get all information about notification music(art cover, song, next, pause, back action)
I search very very much, but can't find the document I need.
If you know, please tell me.
Thank so much!

What you're looking for is a NotificationListenerService. From the docs:
A service that receives calls from the system when new notifications are posted or removed, or their ranking changed.
If you're specifically looking for ways to read Metadata and the music app is using a MediaSessionCompat, you can use MediaControllerCompat.getMetadata() to read the data off of the notification.
To display the actual content of the notification in your app, what you can do is get one of the many RemoteViews from the Notification object you received, then use this answer to display your notification.

Related

Firebase push notification is not working properly when device is offline

I am implement a tap action on the notification and then i found out that when i am offline and triggering the notification. and when i am coming to online i am only receiving the last notification. and it is only happening in android
please help
I have read lot of solution but did not found any proper answer.
I assume you've read this then. Check notification's time to live first, and if you're sure that's not the cause, make sure you're using different notification ids for notifications, otherwise you'll replace the currently shown notification with a new one.
Answered a similar post here. This is working as intended as notification messages are always collapsible.

How to get all active notifications in android?

The question seems familiar and yes I have looked around for the solution but answers are not suiting my use case.
I want to access all the active notifications and use the information before I publish a new notification. I am aware the we can getAllActiveNotifications using the NotificationListenerService (https://developer.android.com/reference/android/service/notification/NotificationListenerService.html#getActiveNotifications())
But this would help me get the notification after notification posted callback is received by receiver. I basically want to check for all active notifications before posting a new notification so that I don't post the notification with same content again.
In order to publish I am using the NotificationManageras follows: NotificationManager nm = mContext.getSystemService(mContext.NOTIFICATION_SERVICE);
nm.notify(tag, id, notification);
I don't want to store the notification ID in database and use that while posting any new notifications.
Thanks for the help in advance!
Update:
It seems this is possible with API23:
https://developer.android.com/reference/android/app/NotificationManager.html#getActiveNotifications()
But I was wondering if there any way to achieve this in 21 or below.

How to get notification count in android?

I have a custom launcher, and I'm showing a custom notification icon
If user clicks on the notification icon he gets to see the notification. This part is working as expected. I can expand the notification list.
But now my requirement is, since I'm using a custom Notification icon I wish to show the notification count(if there are any notification, or if there are 10 notifications). I wish to show the number of unread/unchecked notification user has.
How to get the number(count) of unchecked notification?
I have gone through couple of examples and link like:
Link 1
Link 2
But all these links show how to create notifications, or how to expand notification list. How to get the notification count?
Any piece of code or example is highly appreciable.
Thanks
I would like to share my strategy on how to get the notification count. As I read the documentation, I have not seen any way to store and retrieve the notification count. I am doing a Note Reminder and this reminder alarms at a particular date. Given I have many reminders, sending notification to each of them simply replaces the one on the notification list. This is not nice. Neither my receiver has any way to know the nth time the notification was called. The notification is lack-luster in this case in my opinion.
So, one strategy I saw is to defer the counting responsibility directly to the database. I have to provide a method which returns the number of lapsed reminders I have on the database, tuck it in as an extra on the intent inside the pending intent which launch my receiver. From there I can unpack the extras and set the notification accordingly. This way, I got the information I need and I can model the notification content as such showing the number of reminders that are left untouched. Adding a count badge right next to the icon does not seem possible given the default android but is possible using third-party solutions or using well known android UI like TouchWiz in Samsung, or the one in Xperia. Searching the web, it seems making it so is another different story. I preferred not to do it and simply show through the content I have n count of lapsed reminders.
I hope this help people who are having similar problem regarding retrieving or storing notification count given a unique-per-application notification id.
Hope this helps!
you can use this exemple it work for me
Notification notification = new Notification(R.drawable.direction, "Cool Notification",
System.currentTimeMillis());
/********LIKE THIS*********/
notification.number = notificationCount++;
/********LIKE THIS*********/
notification.setLatestEventInfo(context, "Cool Notification Title",
"updated notificaiton message", null);
NotificationManager nm = (NotificationManager) context.getSystemService(context.NOTIFICATION_SERVICE);
nm.notify(R.id.my_motification, notification);
So you can increment the notification.number every time you display a notification.
If you're targeting API level 18+, then you're in luck, as you can provide a NotificationListenerService to access the current notifications and/or be alerted whenever they are created or dismissed.
Otherwise, you can use the old trick of registering an AccessbilityService and listening on AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED events. This is a good example of this approach.

how to impliment Notifications aggregation

My application displays event notifications, and I'm looking for a way to have notification aggregation.
Meaning, I would like to show 4 notification, but if the fifth comes, I would like to collect all notifications and show only one general notification.
Os there a way to know how many live notifications i have?
Is it possible to approach these notification and cancel them?
Thanks!
According to the android design guidelines you should stack your notifications. So you should avoid showing multiple notification for the same app.
You can stack your notifications using
NotificationManager.notify(ID, notification) where you specify same ID for each notification.
You can check the docs on how to implement it.
For your case
Is there a way to know how many live notifications i have - No
But you can keep a track of the notifications using Shared Preferences, where you store the ID of the notificaion and remove it when the user clicks on the notificaion
Is it possible to approach these notification and cancel them? - Yes
You can cancel a notification using the cancel(int id) method, where you pass the ID of the notification to be removed.
So you can use this method to acheive what you want, but it advisable to stack all the notifications.

Android Push Notification as an invite

I want from my Java server to be able to send an Android notification that will take the form of an invite. I'm currently able to send a basic Android notification, but I want to appear on the screen in form of an invite with options like 'Yes, I accept' or 'No, I refuse' and then send the answer back to the sender. How would you do something like this? I have no clue how should I do it and I can't find anything on the Internet.
Thanks,
Alex
After you receive a pushed message from server, you can launch a new Activity which has a dialog style, then you can do your business in that activity.
the case is very much the same as receiving a sms.
You can create a custom layout for your notification using RemoteViews and manage OnClick events. See Android Notifications, and this question might help you too Create Notification using some controls

Categories

Resources