【问题标题】:Issue with GCM Push notification service DELPHI XE6GCM 推送通知服务 DELPHI XE6 的问题
【发布时间】:2014-10-02 01:12:26
【问题描述】:

我正在 delphi xe6 上开发 GCM 推送通知。 我将这篇文章https://stackoverflow.com/questions/21466094/start-android-activity-before-passing-the-gcm-intent 中的代码(使用AndroidManifest.xml 中的标准组件)用于我自己的应用程序,并且即使应用程序没有运行,我也设法使用该服务来接收通知。

但是当我收到通知时我遇到了一个问题,那就是我无法捕获 onclick 事件,所以我的应用程序打开(很好)但它没有执行所需的操作。

这是我的 AndroidManifest.xml

<receiver android:name="com.embarcadero.gcm.notifications.GCMNotification" android:exported="true">
    <intent-filter>
        <action android:name="com.google.android.c2dm.intent.RECEIVE" />
        <category android:name="%package%" />
    </intent-filter>
</receiver>
<service android:name="com.embarcadero.gcm.notifications.GCMIntentService">
</service>

如果我使用帖子中的代码,我可以检测到用户何时点击通知,但我不知道如何使用标准组件来做到这一点。

问候

【问题讨论】:

  • 当用户打开通知时你想做什么?
  • 这取决于通知。但是,例如,当我使用本地通知时,我可以设置操作并在单击时删除通知。相反,使用推送通知我无法设置“点击”操作,它只会打开应用程序并且点击后通知不会被删除。我希望我把自己说清楚。感谢您的宝贵时间

标签: delphi notifications google-cloud-messaging firemonkey delphi-xe6


【解决方案1】:

AFAIK 您无法从通知列表中删除特定通知 (PUSH)。您必须手动将其删除。

但您可以通过以下方式知道按下了哪个通知并清除所有通知(如果需要):

procedure TFrmMain.ShowMenu;
var
  LNotification: TPushData;
begin
  LNotification := PushEvents.StartupNotification; //Notification that starts the app
  try
    if Assigned(LNotification) then
    begin
      //LNotification is your notification with all your sent data
      //do something here

      //Clear all notifications
      NotificationCenter.CancelAll; //NotificationCenter: TNotificationCenter Component
    end;
  finally
    LNotification.DisposeOf;
  end;
end;

使用 NotificationCenter 组件。

P.S.:我在她的博客中向 Sarina Dupont 提出了这个问题。 Here the answer

【讨论】:

  • 那是使用 Kinvey 通知?还是一般?因为我没有使用 Kinvet 组件
  • 一般来说,你已经将kinvey组件分配给了PushEvent组件。提供者不关心
【解决方案2】:

在我挖掘了许多源代码之后,在 XE6 / XE7 中实现 GCM 客户端没有 kinvy 的最佳和最简单的方法是:

  • 将 TKinvyProvider 拖放到表单上并填写 ONLY GCMAppID 属性,其他保持默认。

  • 将 TPushEvent 组件拖放到表单上,并让 AutoRegisterDevice 为 false。

  • 双击TPushEvent中的OnPushReceive事件,即可获取消息。

  • 双击TPushEvent中的OnDeviceTokenReceived事件,即可获取推送服务器所需的设备令牌。 在这里,您应该将这些信息发送到您自己的 Indy GCM Sever。

  • 转到项目选项,在权利列表中,检查支持推送通知。

  • 在您的项目目录中,有一个名为 AndroidManifest.template.xml 的文件。只需手动添加&lt;service android:name="com.embarcadero.gcm.notifications.GCMIntentService" /&gt; 就在&lt;/application&gt;之前

不再需要自定义的 java 代码!

PushEvents.StartupNotification 在您的应用通过点击推送通知启动时效果很好。您还可以获取该返回对象中的消息。如果您不使用它,您将无法从 OnPushRecevied evnet 获取推送消息(不知何故似乎是一个错误)。

如果您需要 GCM 服务器进行测试,请留下 cmets。我会发送或上传文件。

【讨论】:

  • 我在西雅图德尔福尝试这个,但它似乎不起作用,你在西雅图德尔福得到这个工作了吗?
  • 我想通了,它不是 AutoActivate := True。它是活动的:= True。以上是我相信 Delphi 10 的错误(不确定早期版本)。
  • @FerretDriver 我会注意到同样的技巧似乎也适用于获取 APNs 设备令牌。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-03-18
  • 1970-01-01
相关资源
最近更新 更多