unity-firebase cloud messaging issue - android

I have developed a game with unity and I have used 'Firebase Cloud Messaging' for push notification.
I have one problem. when I clear the received notification in tray, it seems like the message related to it is also deleted. so 'MessageReceived' is not called when I open the app.
I experienced this problem on android. Haven't tested it on ios yet.
I use firebase admin sdk for sending messages.(written with node js)
is there a way to clear notification tray without deleting the message?
thanks for any help in advance

There is some extra setup required to route notifications when the app is not running on Android.
See the Firebase docs for more information
Quote from documentation:
When the app is not running at all and a user taps on a notification, the message is not, by default, routed through FCM's built in callbacks. In this case, message payloads are received through an Intent used to start the application.
Messages received while the app is in the background have the content of their notification field used to populate the system tray notification, but that notification content will not be communicated to FCM. That is, FirebaseMessage.Notification will be a null.
Basically you need to use the custom launch activity bundled with Firebase Messaging instead of the default UnityPlayerActivity. This activity is called MessagingUnityPlayerActivity can can be found inside libmessaging_unity_player_activity.jar. You'll need to create a AndroidManifest.xml file to instruct the app to use this custom activity instead of the default Unity one.

Related

Firebase Push Notifications and Flutter Local Notifications

I've implemented Firebase Push Notifications using Admin SDK for both android and iOS. In iOS i'm receiving notifications on all the stages (Foreground, background or even terminated), but in android I need to integrate Local Notifications again for receiving when app is in foreground. Even I'm successfully integrated it. I need to maintain single notification for particular user. I'm using TAG field while generating Push Notifications whereas in the frontend even i provide the same tag its generating a new notification. So I've added tag as notification_id by converting it to HASHCODE. Now I'm receiving unique notifications using Local Notifications as well.
My problem i'm facing is
For instance consider when my app is in foreground I've generated notification using Local Notifications Package. In the next minute I went to background so I've generated Notification using firebase SDK. In this case I'm seeing 2 Different Notifications for the Same User. One from Local and another from Firebase. In need to maintain single notification for particular user.Can anyone guide to how to solve this.

Send Push Notification to Android app upon the data update in the server, and open custom Activity

Needed a suggestion/idea.
I have to send the push notification to the android app when the data is changed/updated in the server.
I have got a news app, so whenever the news is being updated in the server, the user should get the push notification and when they click the notification, the app should open the link of the news in the app.
What would be the best approach to do so?
I know a bit about FCM, and have played sometime with it, learned about sending the notification from the FCM console, to all the devices using the topic.
Just wondering how can I implement it, rather than using the console, but by just updating the data in the server, and notification should be sent to all the devices which have got the app installed.
You can use your server to send FCM messages to your app without having to use the firebase console manually.
Just a simple API call from the server will push notifications (or messages) to the required devices.
For more information read the documentation on FCM Server.
There are multiple alternatives for opening activity of your choice after clicking the notification.
IMO, a good approach would be to send 'data' field from the FCM server instead of 'notification' field so that the method onMessageReceived will always get called. Inside that method, you can build your custom notification and set the intent to activity of your choice.
Another approach would be to check for extras in the launcher activity and if there is something coming from notification, open the activity of your choice and perhaps finish the launcher activity.

How to send push notifications to Ionic applications?

I am creating mobile application using latest version of Ionic 3. And I am at the point where I need to implement push notifications. I am using FCM. I have managed to done it for Android phones using this plugin: https://github.com/phonegap/phonegap-plugin-push. Reading documentation for this plugin, it says that for Android I should send only Data Messages and that that is the best practice. It also says that send Notification and Data payload would not work properly:
When your app is in the foreground any on('notification') handlers you have registered will be called. If your app is in the background, the notification will show up in the system tray. Clicking on the notification in the system tray will start the app and your on('notification') handler will not be called as messages that have notification payloads will not cause the plugins onMessageReceived method to be called.
But for IOS I need to send notification message with data payload. This would not be a problem if I target directly devices, however I need to send Topic Messages. So the way I see is that on my server I need to implement this logic:
Let's say that the name of topic is FOOD-AND-DRINKS:
function onSomeEvent($data) {
// send push notification to topic ANDROID~FOOD-AND-DRIKS
// send push notification to topic IOS~FOOD-AND-DRINKS
}
Also, since in the future my plan will include multiple cities, and not all people would like to listen for notifications for cities other the one where that person lives, so then my topic would be PLATFORM~CITY~CATEGORY.
So my question would be, is there any better plugin for handling notifications, or some service between my server and Google FCM and that service would take care of that, or this is quite OK what I have proposed?
You can use cloud functions to be able to send notifications since you are using FCM also.
More on this here: https://firebase.google.com/docs/functions/
Cloud Functions for Firebase lets you automatically run backend code in response to events triggered by Firebase features and HTTPS requests. Your code is stored in Google's cloud and runs in a managed environment. There's no need to manage and scale your own servers.
Using cloud functions you can use database triggers like onWrite() and it will be able to send notifications if you have data payload and/or notification.
But if you use data payload alone then you can send if android device is in background also.
Regarding Topics:
If you have multiple cities in your application, then you can let the user register to each topic. You can do in the database like this:
city-category
id_here
cityname: nameX
//other details
id_here1
cityname: nameY
//other details

Notifications handling in apache cordova app

I'm building an apache cordova messaging app (using javascript).
I'm looking for a way to have more control over notifications in my app.
Is there a way to receive a notification and build its text on the client device? I would like to create it in the user's proffered language and use the user's contacts names in the notification itself.
Also, I would like to be able to decide if to show a certain notification when it is received in the device (for example, don't show a notification for a group chat that was silenced)
Is it possible to do when the app is not open at all?
How is it handled differently from native android and iOS apps?
We are talking about push notifications right?
I don't remember the exact function names but think it's quite possible using cordova notification plugin.
So when app is in active/background, you will be able to get the notification object in your callback and decide whatever you do - show it in notification area using local notification, or show in-app alert or just ignore.
When app is closed, system handles the notification and shows in notification area(based on the notification payload APNS/GCMS sends) and when user taps on it, app is launched and a notification handler callback is called inside app.
Anyway, I think what you want to do is quite possible with native apps and cordova plugin since it exposes all of native functionalities.

Send push notifications dynamically with parse.com

I'm making an app that is a news portal, my client wants certain materials are sent via PUSH notifications.
There is the possibility to send notifications via dynamic "code" without using the interface parse.com?
Example: A news reaches 10,000 views, this time I shoot a notification to users who use the app automatically, without any interaction.
Is this possible? If you are unable to parse.com, is there any other service that I can use?
Thank you!
yes this is possible....
just use their cloud code SDK and see the push notification section here
https://www.parse.com/docs/js/guide#push-notifications
the methods declared in cloud code can be accessed from apps native code

Categories

Resources