I need to remove push notifiactions from other apps on notification bar.
I used NotificationListenerService to handle push notifications and then I get push notifications in onNotificationPosted(), it has cancelNotification() to cancel push notification. But i need to have a trigger, when I clicked some button in some fragment notification should remove, is it possible to call cancelNotification() from other place?
val nMgr: NotificationManager = ctx.getSystemService(ns) as
NotificationManager nMgr.cancelAll()
it remove notifications, which you created by yourself, but not from other apps
Related
I have implemented FCM push notifications in an android app.
While I am logged in to the app. I get the notification in the form that I am expecting as below.
When the app is in background I receive the json response instead as below.
Following is the code I have added in onMessageRecieved()
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setContentTitle("App")
.setContentText(messageBody)
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setSmallIcon(R.mipmap.ic_launcher)
.setContentIntent(pendingIntent)
.setStyle(new NotificationCompat.BigPictureStyle()
.bigPicture(bitmap))/*Notification with Image*/;
How can I get the notification in the same manner in both cases.
Any help will be appreciated thank you
After setting up FCM in Android application, you can use Firebase console to send notifications. When foregrounded application receives a notification, onMessageReceived method is invoked. You should override this method to handle notification, but the problem is when the application is in the background and receives a notification, notification delivers to the device’s system tray and you can not handle notification with onMessageReceived method. When the user taps on a notification, it opens the app launcher by default. For example consider you want to do a specific task when a notification is received to the user or do something in background without the user realizing or don’t want to show notification dialog to the user, you can’t do these when the application is backgrounded.
Message Types
With FCM you can send two types of messages to clients :
1- Notification message, sometimes thought of a “display message”
2- Data message, which are handled by the client application
According to Google documents a notification message has a 2KB limit and a predefined user-visible keys. Data messages let developers send up to 4KB custom key-value pairs.
Solution:
If you want to handle notification when the application is backgrounded you should send data message and use onMessageReceived method.
Here is the complete article.
That is so because push notifications handles in foreground and background in different ways.
From the documentation
Notification messages delivered when your app is in the background. In
this case, the notification is delivered to the device’s system tray.
A user tap on a notification opens the app launcher by default.
Messages with both notification and data payload, both background and
foreground. In this case, the notification is delivered to the
device’s system tray, and the data payload is delivered in the extras
of the intent of your launcher Activity.
Also you have to remember that there are 2 types of firebase pushes - Notification message and Data message.
Looks like you are using Notification messages, so they are working as expected.
Just use data type of messages and so you can always handle them as you need.
I'm doing in-app notifications on Android.
I'm using NotificationCompat.Builder and NotificationManager to do it.
I set my notifications priority to PRIORITY_HIGH to display them as a popup.
But the notification is displayed in the Android notifications history. How to prevent this ?
To cancel a notification you call
NotificationManager notificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.cancel(NOTIFICATION_ID);
I would suggest calling this code after you create the pop up so that there is no notification left in the tray. I found this code here: How to clear a notification in Android
I have multiple notifications from my application and the notifications are set to ongoing notification. I want to clear the notification when addaction performs on particular notification.
I can't know the notification id because these are set dynamically. can
Objective: Notification should be auto cancelled on click of it and should open my activity(Pending Intent)..
I have a running code which works perfect in Android Devices expect Nokia-X. Here is the code:
Notification notification = new NotificationCompat.Builder(MainActivity.this)
.setContentTitle(MainActivity.this.getString(R.string.app_name))
.setContentText("text").setContentInfo("info").setTicker("Ticker text")
.setContentIntent(contentIntent).setSmallIcon(R.drawable.ic_launcher).setWhen(System.currentTimeMillis())
.setLights(Color.YELLOW, 1, 2).setAutoCancel(true).build();
NotificationManager nm = (NotificationManager)MainActivity.this.getSystemService(Context.NOTIFICATION_SERVICE);
nm.notify(1, notification);
In case of Nokia-x device, It send notification. It open my activity on click of notification but notification stays in notification tray. It does not get clear on click.
Please help my out!!
It is just like Dr.Jukka said: Notifications cannot be programmatically removed from the Fastlane - only the user can remove content from the Fastlane:
"Currently all notifications are stored in the Fastlane even if the auto cancel flag is used. Do note that if your notification has a command visible from which user can dismiss/remove the notification manually, the notification is not removed from Fastlane. Notifications can only be removed from Fastlane manually by enabling the edit mode."
Furthermore, it does not make sense to have items such as notifications suddenly disappearing from the Fastlane since the purpose of the view is to display the user's/app's past activities.
Hi i've used parse push notification in my android app.
i'm not using noraml notification. i've register parse push notification. The notification alert comes from server
device received the push notification successfully.
for example i've received 10 notification from server, if i open one notification on my device, the app has opened and the one notification has deleted.
My question is,
how to clear the other 9 push notification alert on status bar when open one notification..?
Does android.app.NotificationManager.cancelAll() not work?
If you need to do something very custom, you can use ParsePush to launch an Intent rather than creating a Notification. You can then use a BroadcastReceiver to create Notifications with non-standard behavior (i.e. selective stacking, dismiss all when one is interacted with, etc).
Use this in your launch activity:
String ns = getActivity().NOTIFICATION_SERVICE;
NotificationManager nMgr = (NotificationManager) getActivity().getSystemService(ns);
nMgr.cancelAll();
Use this in your Main Activity
NotificationManager nm = (NotificationManager) get SystemService(Context.NOTIFICATION_SERVICE);
nm.cancelAll;