Search code examples
delphigoogle-cloud-messagingdelphi-xe8android-devicetoken

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 ?


Solution

  • 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;