Xamarin.Forms Push Notifications - android

am implementing push notifications to a Xamarin.Forms app. I included this plugin - https://github.com/CrossGeeks/FirebasePushNotificationPlugin. It works great, the only thing that I am missing is getting push notifications when the app is closed (killed).
Started playing with the sample the plugin authors provide (https://github.com/CrossGeeks/FirebasePushNotificationPlugin/tree/master/samples), just needed to add Xamarin.GooglePlayServices.Base nuget package, the rest is almost untouched. I set up the project in Firebase Console and now I can send notifications from Postman, which looks good:
when app is in foreground then the
CrossFirebasePushNotification.Current.OnNotificationReceived
event is properly triggered
when app is backgrounded then the notification is displayed, jingle is played and when I click it, the
CrossFirebasePushNotification.Current.OnNotificationOpened
event is triggered.
So far so good.
But how to show notification when the app is killed? I supposed it should be done by operating system when notification arrives? But obviously I am wrong or I am missing something. If i send a notification from Postman and the app is closed then nothing happens, no notification is displayed and no event is triggered.
There is also following event handler in MainApplication.cs class that looks promissing but it is also triggered only when app is backgrounded.
//Handle notification when app is closed here
CrossFirebasePushNotification.Current.OnNotificationReceived += (s, p) =>
{
System.Diagnostics.Debug.WriteLine("NOTIFICATION RECEIVED", p.Data);
};
Any ideas how to make this work?
thanks
Jiri

Related

How can trigger onNotification when app in background React Native Firebase

I am investigating about React Native and Firebase Cloud Messaging. In the document, I see that has 2 types of message can be send to client is:
Notification message ( Or Notification and data message )
Data - only message
The first one can be trigger by client using onNotification, and it only trigger if the app on foreground, if in background no way to trigger that has a notification. Just onNotificationOpened can be fired.
The second is inverse, the app can trigger on foreground and background. In case the app has been closed/swiped, on Android luckily it can be triggered also by using a Handler background. But on iOS if the app closed/swiped that no way until we open app again.
The problem is what type of 2 message above that I can use to listen the notification coming, and how it can work if app in foreground, background and closed.
Hope someone can help me about this.

Get push notification payload when opening app, Android Titanium Appcelerator

I have activated push notifications in my application and I have done all the settings with Google and Apple to be able to send from the Appcelerator Dashboard.
I can receive notifications on both Android and iOS without any problems.
In iOS, when i click the notification from the notification center, the application opens and the callback function of Ti.Network.registerForPushNotifications is executed automatically.
The problem is that in Android, the function assigned to the callback event of the cloudPush module is not executed, I understand that it will be because when opening the application the listener is not yet created.
If I receive the notification when the application is open the callback function runs smoothly.
Reading in documentation of Android seems to me to understand that the notification is included in the extras of the intent when opening the application, but I am not clear what extra is, since in Appcelerator I do not find any function to obtain all the extras.
Someone could give me an idea of ​​how to get the payload, whether or not when I click the notification the app is in the background, as if it is totally closed?
Thanks in advance.

Firebase C++ Cloud Messaging background issues

So, I have a Firebase C++ SDK integrated into my Android app and I'm having certain troubles handling my push notifications when my app is in the background.
The thing is that for some reason OnMessage method of messaging::Listener class never gets called when I launch my app through a notification, which is weird, because in a situation when my app is already in foreground when the device gets a notification - OnMessage gets called perfectly fine and I get all the info about the received notification.
AFAIK OnMessage should also be called by the Firebase sdk when a user launches/resumes the app through the notification from the notification bar so that the app could get the payload, but this doesn't happen for me for some reason and I don't know where to look (nothing in adb log, no errors, etc).
Turned out that Firebase Cloud Messaging C++ SDK for Android requires some additional coding that is not described in the integration documentation, but, can be found in the sample app on Github (https://github.com/firebase/quickstart-cpp/blob/master/messaging/testapp/src/android/java/com/google/firebase/example/TestappNativeActivity.java#L35).
When I added the missing code in onNewIntent method - FCM OnMessage callback started to work as expected;

Google Firebase Notifications for Android - when app is not running

I am trying to implement a functionality wherein users get notification messages even when the app is not running (neither in foreground nor in background). Companies like Amazon do send notifications and they show up in the notification tray - when tapped, the app opens or whatever intent the message carried with it.
I have been able to implement notification handling when the app is in foreground and background... but when the app is not running, there are no notification messages received at all!
From what I searched around, I think there needs to be a Service running in the background that keeps listening to notification messages - because a service is destroyed when the app is closed. Am I going in the right direction?
Can someone point me to some code that implements or highlights the same.
FIXED... actually.. the problem was MIUI.. Its security app by default disabled autostart for apps.. which blocks notifications from being shown in the system tray when the app is not running.
References:-
http://en.miui.com/thread-37783-1-1.html
https://github.com/firebase/quickstart-android/issues/89#issuecomment-233558184
I you have to see the implementation of FCM for android from https://firebase.google.com/docs/cloud-messaging/
I shows complete understanding of instant notification.

Air iOS/Android push notification remember when app launches

I have an app built for iOS and Android which has push notifications. Everything is working great however I was wondering if there is a way to store the data of the push notification in the app so that when users launch the app after receiving a notification I can show them the message again?
Basically I allow users to share information and/or chat amongst their friends. If they receive a notification when the app is in the background it comes through as a normal push message but when they launch the app I would like to direct them to the chat feature to see the message again.
I am storing the messages sent in a remote DB but seeing as they have already received the payload it doesn't make much sense for the app to call the remote DB to retrieve the same message.
I am using Distriqt's extensions in AS3 and Air 3.5.
Cheers
I asked Distriqt's support for the same thing a few weeks ago and they explained that there is no way to get the information of the push notification message while the app is closed so they suggested this :
- when the user opens the app, you call your server to check if they haven't missed anything, and get the data from there. If there has been a push, you display the push message as if it was received with the app in the foreground.
It's a bit tricky and not very satisfying but it works.. As long as the user follows the path.
If your user receives the push and chooses not to open your app, he will still get the push message in your app next time he opens it.
I was having trouble figuring this out too but I found a solution! Basically if a user launches an app (not running in the background) by way of a notification it comes through in the Invoke event, not the usual Notification event. So do this:
NativeApplication.nativeApplication.addEventListener(InvokeEvent.INVOKE, invoked);
private function invoked(evt:InvokeEvent):void
{
if (evt.reason == InvokeEventReason.NOTIFICATION)
{
var payload:Object = Object(evt.arguments[0]);
// do stuff
}
}
That's pretty much it. There's more detail in this blog post here: http://blogs.adobe.com/airodynamics/2012/05/29/push-notifications-support-in-ios/
NativeApplication.nativeApplication.addEventListener(InvokeEvent.INVOKE, invoked);
doesn't work correctly for Android push notification. Android starts with InvokeEventReason.standard all the time, so we cant receive message. It works only for iOS.

Categories

Resources