Issue with GCM Push notification service DELPHI XE6
Asked Answered
R

2

0

I'm developing a GCM Push notification on delphi xe6. I use the code in this post https://stackoverflow.com/questions/21466094/start-android-activity-before-passing-the-gcm-intent (using the standars components in the AndroidManifest.xml) for my own app and I manage to use the service to receive the notification even if the app is not running.

But I have a problem when I receive the notification and that is i cant capture the onclick event, so my apps open (great) but it doesn't do the desire action.

Here is my 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>

If I use the code in the post, i can detect when the user click on the notification, but I don't know how to do it with the standard components.

Regards

Randeerandel answered 8/8, 2014 at 14:8 Comment(2)
What are you trying to do when user open the notification?Jung
It depends of the notification. But, for Example, when i use a Local notification i can set the action and delete de notificacion when is clicked. Instead with the push notificacion i'm not able to se te "clicked" action, it only opens the app and the notification is not deleted after the click. I hope i make my self clear. Thanks for your timeRandeerandel
P
6

The best and simplist way to implement GCM client without kinvy in XE6 / XE7 after I dug many source codes is:

  • Drop TKinvyProvider onto the form and fill ONLY GCMAppID property, leave others default.

  • Drop TPushEvent component onto the form and let AutoRegisterDevice to false.

  • Double click the OnPushReceive event in TPushEvent, and you can get message from there.

  • Double click the OnDeviceTokenReceived event in TPushEvent, and you can get the device token nesseary for push server. Here you should send these infomation to your own GCM Sever by Indy for example.

  • Goto Project option, in Entilement List, check support push notification.

  • In your project directory, there's a file named AndroidManifest.template.xml. Just manually add <service android:name="com.embarcadero.gcm.notifications.GCMIntentService" /> right before </application>

No more customized java codes needed !

PushEvents.StartupNotification works great when your app is launched by click on push notification. You can also get what message is in that returned object. If you don't use this, you can't get push message from OnPushRecevied evnet (somehow seems a bug).

If you need GCM server for testing, just leave comments. I will send or upload files.

Fig1

Fig2

Fig3

Fig4

Pernas answered 29/12, 2014 at 14:32 Comment(3)
Im trying this in Delphi Seattle and it doesnt seem to work, have you gotten this working in Delphi Seattle?Deice
I figured it out, It is not AutoActivate := True. It is Active := True. The above is a mistake I believe in Delphi 10 (not sure about earlier versions).Deice
@Deice I'll note the same trick appears to work for getting APNs device tokens as well.Ferriter
J
2

AFAIK you cannot remove a specific notification from the notification list (PUSH). You have to remove it manually swiping it.

But you can know wich notification was pressed and clear all notifications (if you want) with:

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;

using the NotificationCenter component.

P.S.: I asked this to Sarina Dupont in her blog. Here the answer

Jung answered 27/8, 2014 at 13:59 Comment(2)
That is using Kinvey notifications? or in General? Because I'm not using Kinvet componentRandeerandel
In general, you have assigned the kinvey component to PushEvent component. The provider doenst careJung

© 2022 - 2024 — McMap. All rights reserved.