Removing specific notification when you don't know the notification id? - android

How can I remove a specific notification when I don't know the notification id (when app was not running and OS generated the notifications)? I don't want to use notificationManager.cancelAll() because there are multiple types of notifications and I can't use notificationManager.cancel(id) because I don't know the ID of that notification.
I've already gone through most of the SO threads so please don't mark it as a duplicate of the following:
How to clear a notification in Android
How to remove an android push notification from notification center when the app gets started by its launcher icon?
How to remove push notifications that have already been sent?
How to remove an android push notification from notification center when the app gets started by its launcher icon?

Related

Set Firebase Notification to appear as Popup like whatsapp in Android studio

I am building an social media app in Android studio, this app uses firebase for push notifications, and notifications is working fine, that Is notifications shows on device's notification bar.
How can I change the behavior so that the notification can appear as popup when app is in foreground?
I want a persistent kind of notification, something like WhatsApp that can stay on top other apps so that users can quickly open notification on wherever they are on their phone.
On my research, the best i could get was to use this on my theme
But I do not have Theme.Holo.Dialog in my style and my aim is that the notification should appear even if app is not open.
Thank you for looking into this
You should use heads-up notifications
For this purposes you should use notification channel with high a importance: How to set importance in the notification channel.
In this answer you can find code sample, how to show notification in the channel with high importance(to show notification even if the app in the foreground):
https://stackoverflow.com/a/67953864/16210149
Hope it would be helpful.

Show firebase notifications when android app is open and with high priority

I am using nativescript-plugin-firebase for the APP and I get the notifications when the app is closed.
However, if the app is open I don't get any notifications. Is there any way to force showing push notifications even when the app is open or do I have to create a custom notification with sound within the app?
Another problem that I have is the way the push notifications are displayed. I use Laravel-FCM to send push notifications from the server-side, I have the priority set to 'high' and everything else set to default but when I receive the notification to the android device there is no floating notification, only a badge icon and a notification in the notifications center.
In the app notifications settings, there is Miscellaneous Notification Category with Importance set to Default, Vibration set to OFF and LED Light is also OFF but if I manually change those settings then firebase notifications appear with floating notification and vibration.
Any way to actually make these notifications with high priority by default?
P.S. The device I am testing on is Xiaomi Redmi Note 8 Pro
I have the same problem when using Nativescript-firebase as yours. When the app is open, the push notification is delivered but not shown (see onMessageReceived callback) then you can use Nativescript-local-notification to show the content of the push notification received when app is open.

Cordova push notification not working when app is in background

I have implemented push notification in Cordova application by using following plugin
https://github.com/phonegap-build/PushPlugin
It's receiving notifications in application(but Not in notification area).
But when my app is in background it does not show any notification.
So it's working only when app in foreground.
So, I have 2 questions :
How to show received notification in notification area?
How to received notification even my app is in background?
I got my answer.
First go through GCM documentation, then I realize that I was not sending 'message' in 'data' parameter of push notification.

How to change notification of other apps programatically (with root or not)

Is it possible to change posted notification of other app (replace on notification from my app). I know in android 4.3 exist feature of reading notifications (https://developer.android.com/reference/android/service/notification/NotificationListenerService.html) but i need to replace existance notification on notif from my app.

How to receive Parse push notification only when app is opened, and show it in modal dialog form

I was using https://github.com/ParsePlatform/PushTutorial sample code for a while.
Current example behavior is
Push notification will be received, either the app is opened or closed.
Push notification is in the form of showing icon in status bar with sound.
I cannot find a way to specific notification icon image. Parse is using app icon as notification icon by default. By Android design guideline requires us to have different style and size for notification icon.
When the app is opened, and notification received. Clicking on the notification icon will cause 2nd instance of the same app is launched. That's mean, there will be 2 instances of same app. (Personally, I don't feel this is a correct behavior)
I was wondering
How can I only receive the push notification when app is opened, but not closed?
How can I show it in the form of modal dialog, instance of showing icon in status bar with sound?
I am not sure about the 4th point, it didn't work that way for me. It opened the same instance for me. I think you are using a different application identifier and have two different application with same name and icon, but different identifier.
Now, for your use case, I think Push notification is not the ideal solution. Depending on what and how frequent you need to show this, you may opt for a repeating pull from the server or if you still want to use Push Notification then subscribe/unsubscribe from a Push Notification Channel when the app is pulled to foreground or background.
ie, when the application is in foreground (onStart() / onResume()), subscribe to a channel:
PushService.subscribe(context, "foregroundPush", YourActivity.class);
and when the application is moving to background (onStop() / onResume() / onDestroy() ), unsubscribe from the same channel:
PushService.unsubscribe(context, "foregroundPush", YourActivity.class);
Whenever you need to send a push notification to the devices with your application in foreground, use the channel 'foregroundPush'

Categories

Resources