Android GCM:通知解除后重复推送

时间:2015-08-21 10:04:56

标签: android notifications google-cloud-messaging

我正在向GCM发送一条通知给Android设备并且它正确到达,但有一种情况是在被解雇后显示通知。重现的步骤:

  1. 打开启动服务的应用程序以接收通知。
  2. 发送带有 try: curses.cbreak() while True: key = shell.getch() if key == 119: print("key w pressed") sleep(0.03) except KeyboardInterrupt: curses.nocbreak() 有效负载的gcm消息。
  3. 通过向左/向右滑动此通知来关闭通知。如果它具有notification元素,则单击它也是有效的。
  4. 打开任务并关闭当前的应用程序。
  5. 再次打开该应用程序。当GCM服务再次启动时,它会收到先前被解雇的通知。
  6. 我的代码是Google使用action_click提供的example中最基本的代码。只需设置权限,将服务放入清单中,然后让google显示通知。当提供的场景发生时,我在服务的GcmListenerService中被调用两次并使用相同的数据。

    这是我发送给GCM的通知负载:

    onMessageReceive

    修改

    • 我使用的是{ collapseKey: 'push', delayWhileIdle: true, timeToLive: 3600, data: undefined, notification: { body: 'test message 2 updated', title: 'Notification', icon: 'myicon' }, contentAvailable: false } 版本,但也使用了7.5
    • 进行了测试
    • 我可以重复这个过程5次,之后,通知会永远被解雇。

1 个答案:

答案 0 :(得分:1)

我终于解决了这个问题。使用新的GCM实现,无需启动提供信息的服务,Google是否根据推送选项在需要时启动它。

因此,如果您的代码中包含以下内容,删除

//This service extends GcmListenerService
Intent intent = new Intent(GCMNotificationService.class, context);
context.startService(intent);

您将停止缓存通知的问题,接收两次相同的通知和一些奇怪的其他行为。