In my app I have notifications which can be showed when application is not running. When I open and close application, notifications disappear.
Is it normal situation? Is there any method to keep notifications?
Make sure that there is no any other service or project module, which does the following call NotificationManager.cancelAll() to cancel all the notifications. It is always better to keep the notifications controller over Unique ID and cancel only the notifications which are related to that part, by this the code won't touch the notifications posted by other project parts.
For more reference follow Notification Manager:
https://developer.android.com/reference/android/app/NotificationManager.html
Related
I have noticed that when I send a push notification (Firebase Messaging Service) to my device my Application object is created. This is without clicking on the notification. Simply the act of viewing the notification creates the application. Further, it also starts the Jetpack AppStartup library. I want to be able to use AppStartup and application create. But I don't want to launch that code when a push notification occurs.
Why does Android do this? Is this part of all android notification, or is it a feature of the third-party push notification sdk I am using? And is there a way in Application.create and AppStartup to distinguish a normal app launch from a push notification triggered launch?
Again, I'm not talking about the user clicking on the notification (and launching the app because of a deeplink). I'm talking about just looking at the notification in the notification dropdown.
Why does Android do this?
Android is starting your app process to run code in your app. Creating an Application instance and calling onCreate() will be part of that, as will creating any ContentProvider objects. IIRC, Jetpack Startup uses a ContentProvider to get control early in your process, though I am not 100% certain of that.
The reason why Android is starting your app process is because your app is causing the Notification to be displayed — specifically, Firebase Cloud Messaging is doing that. If I remember the protocol correctly, Play Services is sending a broadcast Intent that Firebase Cloud Messaging in your app will respond to, and part of that code will be displaying the Notification.
And is there a way in Application.create and AppStartup to distinguish a normal app launch from a push notification triggered launch?
onCreate() of an Application subclass has no means of knowing what specifically caused the process to be created, as there can be many possible reasons. If by "AppStartup" you mean Jetpack Startup, I do not recall it having any options here, but I have not spent much time with its API.
I am using react-native-firebase for the push notifications and it works fine. I am also using CallKeep for handling VoIP calls. I want to display an incoming call when the app gets a notification while it is killed or in background (ex. like WhatsApp).
Regarding to the documenation if a message is received "the device silently starts your application in a background state. At this point, your background handler" code is triggered. But this does not happen. The handler is trigger only if I tap the notification.
I've also added some code in AppDelegate.mm like mentioned in the description but it not works.
BTW: I am currently on iOS and don't know how the effect is on an Android device.
So how can I achieve this, or it is even possible ?
So I found the solution. The problem was that I used firebase console to send a notification which did not contain "ContentAvailable: true" property. When I send a notification using the C# sdk including "ContentAvailable = true" then the background handler is called, even if the app is in background or killed.
I implemented firebase into my app to use it's notification service a while back and it worked, and today decided to use it's key/value feature, but realized that no matter what I write in my class inherited from FirebaseMessagingService, nothing happens. So I decided to remove the my class for dubugging purposes, and I still got notifications. So I removed the firebase messaging service from the manifest, deleted the app cache and ran the project, but I still get notifications! The only way I can prevent notifications from coming is to remove the firebase dependency in gradle. What's happening here?
Just read the documentation.
...
Ok, let's go: there are three kind of "notification" using Firebase: notification messages, data messages and messages with both notification and data. Each is received and handled differently by the system. Here you can see more information about message types (how there are built).
There are handled like that:
Notification message
App in foreground: onMessageReceived's implementation
App in background: system tray (system dispatch automatically notification) -> with or without service implementation (maybe your case, without code I can't know)
Data message
App in foreground: onMessageReceived's implementation
App in background: onMessageReceived's implementation
Message with both notification and data
App in foreground: onMessageReceived's implementation
App in background: system tray (notification) and in extras of the intent (data)
But without any code or notification information, I can't continue to help you. Until you provide some code example, I only think that you send a notification message, and so system automatically display a notification and there is no call to the service's onMessageReceived, it's normal.
If you want to "control" and decide if notification should be shown or not, just send data messages, and in your onMessageReceived implementation, create a notification with content and intent and notify it to the system (if you want it to be shown).
Android notifications disappear after some time, without touching it to cancel. What could cause this kind of problem? The notification is started in a Service.
Is that possible that the low memory causes this kind of problem?
Make sure that there is no any other service or project module, which does the following call NotificationManager.cancelAll() to cancel all the notifications. It is always better to keep the notifications controller over Unique ID and cancel only the notifications which are related to that part, by this the code won't touch the notifications posted by other project parts.
NotificationManager documentation.
I am using Parse API in order to handle push notifications. In our Android application, I want to accomplish two things:
1) If we have received a Push Notification with the application is closed and the user clicks on the notification, I want to be able to understand that the application is being opened via a push notification.
2)If we receive a push notification while the application is open, I want to handle this and do some extra work.
In both cases, I want to be aware that the application has received a push notification in order to execute some special operations.
As far as I understand from Parse API documentations, it offers two methods of handling pushes: Responding with an Activity and Responding with an Intent. I am currently calling
PushService.setDefaultPushCallback(context, MainActivity.class);
in my Application class with needed changes in the AndroidManifest.xml file and already receive push notifications, this corresponds to Responding with an Activity method. But I don't know how to be aware of Push Notifications explicity with this method.
Thanks in advance.
When a push is received ,Check
1:Whether our application is in foreground or background.
If it is foreground, that means app is visible and do your stuff(show alerts or anything you want).
If app is in background,that means it is not visible and if you want to do any thing based on this.
i hope this helps..