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.
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.
Is there any way in flutter to identify if the App has been opened by clicking on the App Icon or by some other options like Push Notification or deep linking.
If there is a way to identify the App has been opened by clicking on the App Icon I can deal with the other cases.
I tried to play with WidgetsBindingObserver but all it could give me is the state of the application or it is possible that somehow I'm missing some obvious part!!
N.B -- I'm not using Firebase Messaging.
For Flutter push notifications through firebase, you can use the following callbacks to check if the app is opened through push notification
onMessage: if the app is currently running (foreground) it will return you a stream of remote messages
onMessageOpenedApp: When the app is in background mode and the user has opened it using push notification, it will return you again stream of remote messages
Note: it will not work if the app is terminated or not running for the following method is used
FirebaseMessaging.instance.getInitialMessage(): it will work if the app is opened through push notification when it was in termination state, return a remote message not a stream of messages
Hope this will be helpful
Thanks
FCM Unity plugin gives you message received callback only when your app is in foreground because that is when you can register fro callback.
I am developing a plugin which shows notification, is there any way where I can get message data when app is in background to show push notifications?
As we know Unity engine is a foreground process, so we can not expect Unity to run scripts while the app is closed.
But firebase can itself run in the background regardless of app's engine state.
It will receive the message and save it in the intent of the activity, so when the user opens the app the activity will run and the intent data will be passed to onMessageReceived.
According to documentation, to achieve this, you need to use com.google.firebase.MessagingUnityPlayerActivity instead of UnityPlayerActivity.
Or if you cannot do this and are extending some other activity neighther firebase's, check this part of the docs.
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;
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.