Firebase push notification not shows when the app at foreground in android platform - nativescript

I am developing both android and iOS application using the nativescript-angular framework. I am using a nativescript-plugin-firebase plugin for the fcm push notification. In the iOS platform, the notification is coming both in the foreground as well as in the background. But in android, the notification is coming only when the app is in the background.
How do we fix this issue?
My firebase initialization code:
firebase.init({
showNotifications:true,
showNotificationsWhenInForeground:true,
onPushTokenReceivedCallback:(token)=>{
console.log("onPushTokenReceivedCallback:",{token});
},
onMessageReceivedCallback:(message:firebase.Message)=>{
console.log("onMessageReceivedCallback:",{message});
})
.then(()=>{
console.log("Initialized");
})
.catch(error=>{
console.log("Initialize",{ error });
});

I'm struggling with Notifications too right now,
you can use Nativescript-Local-Notification plugin alongside with firebase plugin like me, you can have much more customized notifications and can handle them much better in client-side.
just schedule a local notification when you get your firebase callback.
it perfectly works in the foreground, I'm struggling to make it work in the background, in the background I just keep getting Firebase notification, can't disable it.

Related

Xamarin Forms Push notifications not received properly when the app is closed in android

We have configured push notifications in our Xamarin Application for both android and iOS. In iOS notifications are being received properly. But in Android, specifically when the app is closed the notifications are not being received properly.
When the app is open, push notification is triggered and displayed properly as expected, can be observed in the screenshot attached.
When the app is closed, push notification is triggered and displayed as "body", can be observed in the screenshot attached.
Note* Notifications are being sent from ASP.net core with Azure Notifications hub.
The payload looks like below : new JObject(new JProperty("notification", pushMessage)).ToString(Formatting.None);
Andoid Notifications
I tried changing notification payload in different ways but still result didn't change.

Android Auto custom notification sound

I have created a messaging app that support Android Auto and is able to push notifications to it.
My problem is that I can not override the notification sound for my notifications.
I have tried to set sound on Notification Builder and on Notification channel but no luck.
From the documentation, those methods are not forbidden.
Does anyone has an idea if is possible?
I'm also curies if is possible to force Android Auto to auto read the message without waiting the user to click on play button?

Azure Notification Hub losing the subscribe when app is reinstalled

I have a problem with Azure Notification Hub.
When my app is started in first time, the notifications working correctly, but when did a rebuild the app by Visual Studio, the notifications stop working and the Android Services with IntentFilters do not are called.
For the notifications works again, I need to uninstall the App in Android and run by Visual Studio again.
Have someone some idea about that problem?
My worry is: if I send the app to GooglePlay, the notifications would continue working after a update?
If someone know how to call the service to get the new InstallationId, always that the app to be started I will know how I can resolve the problem.
Can someone help me?
I did follow that tutorial:
https://www.youtube.com/watch?v=le2lDY22xwM&t=3312s
if I send the app to GooglePlay, the notifications would continue working after a update?
There is no need to worry about that, referring to this document, when you use Azure Notification Hub, it's using Android GCM to send the push notificcation. You could see my answer about Android using Firebase Cloud Messaging not receiving message.
As the Official document said :
On initial startup of your app, the FCM SDK generates a registration token for the client app instance. If you want to target single devices or create device groups, you'll need to access this token.
Explanation about Token :
An ID issued by the GCM connection servers to the client app that allows it to receive messages.
When you did a rebuild the app by Visual Studio your token is changed, but it didn't trigger the OnTokenRefresh method, so at this time the Token in your application is invalid. That's why your application cannot receiving message.
For more information, you could refer to Sending Push Notifications from Azure Mobile Apps and Implement the Firebase Instance ID Service.
When your app get a update, it will trigger the OnTokenRefresh method automatically, so your application can still receive the message.

How to get app message from companion app if Pebble app is in background?

"I am explaining whole scenarios here in order to avoid multiple discussion threads, as I am looking for quick help, so providing here all the details."
I have created a application which communicates with the android companion app, which has some of events scheduled and needs to send to pebble app, so that even if the timeline is muted for our app we can provide important information to pebble app user.
I am able to get the data from companion app and process it successfully only if the pebble app is open but my one more requirement is :
To get data in pebble app sent by companion app, even if my pebble app is in background.
ie. If the companion app sends me some message but the pebble app is in background so I should be able to read that message and wake up the Pebble app to show the desired information.
I am using "App Message" for communication between Companion app and Pebble app.
I gone through the Pebble Documentation which states :
"Background workers do not have access to the UI APIs, they also cannot use theAppMessage API or load resources. Most other APIs are available includingAccelerometerService, CompassService, DataLogging and Storage."
One more Query is :
As we can get notification in our Pebble if its came to Phone, so is there any way to open some desired app or related app to that message in Pebble watch.
Please guide me if there is anyway to get this done.
Thanks in advance.
Your Android application can launch the watchapp before sending the message to her. That should solve your problem.
As indicated in the documentation, the background worker on the watch cannot receive app messages.

handling push notification while app is running in background

I have implemented push notification in my app and it works fine when the app is not running. But when my app is send to background then no alert is being displayed regarding the push notification. What do I need to do so even if my app is in background I can display alert for push notification.
Any help would be appreciated.

Resources