I am implementing push notification in Android ported BB 10 app. I am using Push Sharp in sevrer side to send notification. Below is my code:
bbBroker.QueueNotification(new BlackberryNotification
{
Recipients = new List<BlackberryRecipient> { bbReceipent },
Content = new BlackberryMessageContent(json),
SourceReference = "myappid"
});
bbBroker.OnNotificationSucceeded += (notification) =>
{
Log.WriteLog("BBB Notification Sent Successfully");
};
OnNotificationSucceeded is called, but in my device I don't see any notification.
One time I heard only sound and red color icon on my app. I was not aware how to view notification, I uninstalled the app, then again installed it. Then I pushed some text, but now even sound also stopped coming.
Please someone guide me what is going on?
Related
I have a Flutter application using the firebase-messaging plugin for push notifications.
I register firebase like normal on the client, and I send the fcmToken to the server.
Notifications are created via a python server using aiofcm (which uses firebase's XMPP api). They're created like this:
message = aiofcm.Message(
device_token = t2,
notification = {
"title":notification_title,
"body":notification_body,
"sound":"default",
"tag":link
},
data = {
"click_action": "FLUTTER_NOTIFICATION_CLICK"
},
priority=aiofcm.PRIORITY_HIGH
)
await fcm.send_message(message)
On iOS, notifications pop-up at the top of the screen.
On Android, only the icon shows up in the notification tray - not any of the notification content. This is tested on a Pixel 3 and a OnePlus 6, both running Android P.
Ideally, I would like the notification to be "heads-up" style like this:
Before I was able to accomplish this using data messages and creating the notification programmatically in native android, however I would like to avoid that if possible since data messages don't get delivered on Android if the app is terminated.
To Get heads-up - Notification - Kindly set "alert: true"
Example :
notification = {
"title":notification_title,
"body":notification_body,
"sound":"default",
"alert" : true
"tag":link
},
For heads up notification you will need to use flutter_local_notifications Plugin. It is even recommended in FlutterFire official documentation for notification to show notification in foreground (background notification also supported ofcourse!) and it shows heads up notification by default.
You should check out the firebase.flutter.dev docs it shows how to do this easily with the help of flutter_local_notifiation
you can use background fetch and local notification package for background app running.
I'm using react-native-firebase with firebase-messaging to implement push notifications.
While I can send push notifications to everyone, I'm unable to send them to individuals. To my knowledge, all I need is the FCM Registration Token which I retrieve by following the documentation
firebase.messaging().getToken()
.then(fcmToken => {
if (fcmToken) {
console.log("fcm token", fcmToken);
} else {
console.log("fcm token", "null");
}
});
The token I receive is a plausible token, but when I copy that token from the logs into the firebase console and try to send it to a single device, nothing is received. (If I push to a user segment, it's received by all devices with the app installed).
As I can not test for iOS, this might or might not also be a problem on iOS.
In my build.gradle file, the firebase relevant libraries are included like so:
compile(project(':react-native-firebase')) {
transitive = false
}
implementation "com.google.android.gms:play-services-base:15.0.1"
implementation "com.google.firebase:firebase-core:16.0.1"
implementation 'com.google.firebase:firebase-auth:16.0.2'
implementation "com.google.firebase:firebase-messaging:17.1.0"
In the MainApplication.java file I add them to the list of ReactPackages.
new RNGoogleSigninPackage(),
new RNFirebasePackage(),
new RNFirebaseMessagingPackage(),
new RNFirebaseAuthPackage()
My AndroidManifest does not have any Firebase relevant changes as I discovered that push notifications were working even without them. (While trying to implement push notifications I noticed that all phones were receiving them except the one I was actively working on - so I rolled back the code.)
edit: I managed to receive one single device notification. Without any changes, it was suddenly working exactly once. Now it doesn't work anymore.
I would like to know if there is a way to find out if an app is launched because of a notification opened event.
Currently when a user taps on an incoming notification, OneSignal will resume/launch my application and it will call the handleNotificationOpened handler of the app where I can process the notification without any problems as well as redirect the user to specific page in my app based on the notification's payload.
The issue that I want to solve is that if my application is not running, then OneSignal will launch the app and it will show the default root page of my app for less than a second and then the user will be redirected to the proper page. What I would like to achieve is to prevent showing the app's root page and only show the notification handling page upon clicking on the notification, thus I need to know if there is a way to identify the fact that the app was launched because of a notification tap.
Does anybody have an idea on how to achieve this?
Thanks
As I wasn't able to find a way to check launch parameters or anything like that to verify that the application was launched for processing a notification tap I tried tackling the problem from another angle.
For anyone interested in a possible "workaround" I have posted a possible solution. Please do not assume this is a definite solution but rather treat it as a suggestion and by no means do not push this onto your production environment without exhaustive testing.
constructor (platform: Platform, private statusBar: StatusBar, private oneSignal: OneSignal) {
var isNotification = false;
platform.ready().then(() => {
this.statusBar.styleDefault();
setTimeout(() => {
if (! isNotification) {
this.rootPage = FirstRunPage;
}
},3000);
var iosSettings = {
kOSSettingsKeyAutoPrompt: false,
kOSSettingsKeyInAppLaunchURL: false
};
this.oneSignal.startInit('replace with Onesignal id');
this.oneSignal.inFocusDisplaying(this.oneSignal.OSInFocusDisplayOption.Notification);
this.oneSignal.iOSSettings(iosSettings);
this.oneSignal.handleNotificationOpened().subscribe((data) => {
isNotification = true;
this.nav.push("NotifyHandlerPage");
});
this.oneSignal.endInit();
});
}
I'm developing an app in Windows Phone 8.1 (NOT silverlight) which uses WNS to receive raw push notification.
While I run my app through Visual Studio (over a physical device, not in the emulator), I always receive push notifications (with the app in foreground, in background, with the phone locked...) so I think my code to receive push is correct.
My issue is when I run my app whithout using Visual Studio. If I press the "app icon" on the device to init the app and keep it in foreground, I receive push notifications. But if I go to the phone menu, or lock the device (without killing the app), I don't receive push notifications, but the server says that WNS has been sent successfully. If I put the app again into foreground, I receive push notifications again...
So, summarizing: Init app through Visual Studio, I receive always the WNS notifications. Init app through device, only receive WNS with the app in foreground. The server always send the WNS successfully.
Here is my code to receive WNS:
public static void OnPushNotificationReceived(PushNotificationChannel channel, PushNotificationReceivedEventArgs e)
{
Debug.WriteLine("Received WNS notification");
string notificationContent = String.Empty;
switch (e.NotificationType)
{
case PushNotificationType.Badge:
Debug.WriteLine("Badge notifications not allowed");
return;
case PushNotificationType.Tile:
Debug.WriteLine("Tile notifications not allowed");
return;
case PushNotificationType.Toast:
Debug.WriteLine("Toast notifications not allowed");
return;
case PushNotificationType.Raw:
notificationContent = e.RawNotification.Content;
break;
}
processWnsNotification(notificationContent);
}
//Show local toast notification
private static void processWnsNotification(string notification)
{
ToastTemplateType toastTemplateXml = ToastTemplateType.ToastText01;
XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(toastTemplateXml);
XmlNodeList toastTextElements = toastXml.GetElementsByTagName("text");
toastTextElements[0].AppendChild(toastXml.CreateTextNode("New message"));
ToastNotification toast = new ToastNotification(toastXml);
if(toastNotifier == null)
{
toastNotifier = ToastNotificationManager.CreateToastNotifier();
}
toastNotifier.Show(toast);
}
Anyone know what happens or what I'm doing wrong?
I think it could be a configuration issue... but I've been digging into property and config files without success.
Thanks a lot!!
Jorge.
This is the expected behavior and is very well documented, that your app will receive raw push notifications only when it is not suspended or when a background task is registered which can handle raw notifications.
You receive them when Visual Studio is open because when the debugger is attached the app does not suspend. To debug the suspension of an app, go to View->Toolbars and enable the Debug Location toolbar, then start your app, and select the Suspend option from the Lifecycle Events box. You will notice that your code does not execute (test with breakpoint).
The notification may be sent by your server, but will not be received by your phone. You probably don't check the responses of your push requests, but there should be some indication that the client is not available or something similar (a status code that states that maybe).
I have tested to send push notifications with cordova-1.8.1.js and the push plugin together with pushwoosh.com and it work as it should.
I followed this tutorial: http://www.pushwoosh.com/programming-push-notification/push-notification-sdk-integration-for-phonegap/
The push notification is send to my iPhone and it plays the sound and shows the notification when the phone and app is closed, good!
But if I open the phone when the notification is visible then the app is opened as it should...but
the alert that is displayed is saying:
Alert
"push-notification","{\aps\":\sound\":\"default\",\"alert\":\" and then the message....\"}}”
So what is wrong, it should only write the message in the alert and not the rest?
Also if I delete the app with home button and start it again I get another alert saying "registerDevice", "type":"7".....and so on.
2. How can I make this go away?
Any input appeciated, thanks!
Problem solved. Use this and it will only show the message in the alert and nothing else.
document.addEventListener('push-notification', function(event) {
//console.warn('push-notification!: ' + event.notification);
//navigator.notification.alert(JSON.stringify(['push-notification1!', event.notification]));
var notification = JSON.parse(event.notification);
navigator.notification.alert(notification.aps.alert);
//pushNotification.setApplicationIconBadgeNumber(0);
pushNotification.setApplicationIconBadgeNumber(0);
});