Egemen HALICI
Egemen HALICI

Reputation: 33

Delphi Xe8 , How to get android device token?

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 ?

Upvotes: 0

Views: 1787

Answers (3)

Kajisensi
Kajisensi

Reputation: 63

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;

Upvotes: 0

shyambabu
shyambabu

Reputation: 163

  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;

Upvotes: 2

mwroh
mwroh

Reputation: 46

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;

Upvotes: 3

Related Questions