Android上的通知托盘上不会显示解析推送通知

时间:2015-02-09 19:02:29

标签: android parse-platform push-notification ionic-framework

我有一个使用Ionic Framework开发的Android应用。我使用ngCordova plugin for push notifications并使用parse.com发送它们

应用程序运行时会收到通知,但当应用程序在后台时,通知托盘上不会显示通知。我收到这样的话:

notification = {
  payload: {
    data: {
      alert: "message",
    }
  }
}

但是,当我通过CGM直接发送时,通知确实出现在通知托盘上。我收到的对象就像:

notification = {
  message: "this appear on notification tray",
  payload: {
     message: "this appear on notification tray"
  }
}

Parse有什么问题吗?或者是我对Parse缺少的东西?

1 个答案:

答案 0 :(得分:0)

这是一篇很老的帖子,但是我使用 Xamarin 和Parse Push通知来解决这个问题,但我的工作可能适合你(以及其他可能在将来看到这个的人)

收到Parse通知后,我结束了广播本地推送通知。

首先将接收器分配给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);
}

希望这可以帮助您和遇到此事的任何其他人!