解析推送通知不会出现在Android上的通知托盘上
问题描述:
我有一个使用Ionic Framework开发的Android应用程序。我正在使用ngCordova plugin for push notifications并使用parse.com发送它们解析推送通知不会出现在Android上的通知托盘上
当应用程序正在运行时收到通知,但当应用程序在后台时通知未在通知托盘上显示。我收到类似这样的内容:
notification = {
payload: {
data: {
alert: "message",
}
}
}
但是,当我通过CGM直接发送它们时,通知确实会出现在通知托盘上。我收到的对象是:
notification = {
message: "this appear on notification tray",
payload: {
message: "this appear on notification tray"
}
}
Parse有什么问题吗?或者我错过了关于Parse的内容?
答
这是一种旧帖子,但我用Xamarin和解析推送通知来解决此问题,但我的解决方案可能适用于您(以及将来可能会看到此问题的其他人)。
收到Parse通知后,我结束广播本地推送通知。在方法
ParsePush.ParsePushNotificationReceived += PushNotificationReceived;
然后:
首先分配一个接收器解析通知事件
void PushNotificationReceived (object sender, ParsePushNotificationEventArgs e)
{
var payload = JObject.Parse (e.StringPayload); // Parse the JSON payload
Notification.Builder builder = new Notification.Builder (this);
builder.SetContentTitle (payload ["alert"].ToString());
builder.SetContentText (payload ["androidDetail"].ToString()); // Note: this is another field I added to the Parse Notification
builder.SetDefaults (NotificationDefaults.Sound | NotificationDefaults.Vibrate);
builder.SetSound (RingtoneManager.GetDefaultUri (RingtoneType.Notification));
builder.SetSmallIcon (Resource.Drawable.small_notification_icon);
var largeIcon = BitmapFactory.DecodeResource (Resources, Resource.Drawable.large_notification_icon);
builder.SetLargeIcon (largeIcon);
var notification = builder.Build();
notification.Defaults |= NotificationDefaults.Vibrate;
NotificationManager notManager = (NotificationManager)GetSystemService (Context.NotificationService);
notManager.Notify (0, notification);
}
希望这有助于你和其他人谁碰到这个来了!
嘿,你可以请你分享你的代码(你使用ngCordova设置Parse推送通知的方式) – 2015-03-27 18:43:04