0

I registered Google Cloud Messaging(GCM) system. I am using Delphi Xe8 .

I need to get android device token for send notification with gcm.

But I have no idea about device token.

How can I get device token ?

  • Your question is answered here: http://stackoverflow.com/questions/18838485/google-cloud-messaging-in-delphi-xe5 The second answer provides a link to a example component, which uses JNI to use the GCM-functionality (https://sites.google.com/site/ioanghip/TGCMReceiver.zip?attredirects=0&d=1) – Stefan Wanitzek Jun 17 '15 at 16:50

3 Answers3

3

You can get the DeviceID and DeviceToken using follow code...

var 

    ADeviceID, ADeviceToken : String; 

begin

    APushService := TPushServiceManager.Instance.GetServiceByName( TPushService.TServiceNames.GCM );
    APushService.AppProps[ TPushService.TAppPropNames.GCMAppID ] := '123...GCMAppID...456';  // Your GCM App ID
    AServiceConnection := TPushServiceConnection.Create( APushService );
    AServiceConnection.Active   := True;
    AServiceConnection.OnChange := OnServiceConnectionChange;
    AServiceConnection.OnReceiveNotification := OnReceiveNotificationEvent;
    ADeviceID    := APushService.DeviceIDValue[ TPushService.TDeviceIDNames.DeviceID ];
    ADeviceToken := APushService.DeviceTokenValue[ TPushService.TDeviceTokenNames.DeviceToken ];
end;
Mohit Kanwar
  • 2,962
  • 7
  • 39
  • 59
mwroh
  • 46
  • 3
2
  p : TJavaObjectArray<JString>;
begin
  gcm :=   TJGoogleCloudMessaging.JavaClass.getInstance(SharedActivity.getApplicationContext);
  p := TJavaObjectArray<JString>.Create(1);
  p.Items[0] := StringToJString('GCM Project Id');
  Memo1.Lines.Add(JStringToString(gcm.register(p)));
end;
shyambabu
  • 169
  • 11
0

If you are following this manual http://docwiki.embarcadero.com/RADStudio/XE8/en/Multi-Device_Application_to_Receive_Push_Notifications

Then at the point on this manual where you make events from PushEvents1 You can get Devicetoken by this code.

procedure TForm1.PushEvents1DeviceTokenReceived(Sender: TObject);
begin
ShowMessage('Devicetoken received');
ShowMessage(PushEvents1.BindSource.Adapter.PushSender.DeviceToken);
end;
Kajisensi
  • 43
  • 6