Firebase Android Support C++ code?

This is the forum for miscellaneous technical/programming questions.

Moderator: 2ffat

Firebase Android Support C++ code?

Postby Lena » Tue Jul 23, 2019 2:34 am

Hello.
Can anyone translate this code into C++?
I do not understand for example:
if (TPushService.TChange.Status in PushChanges)...
http://docwiki.embarcadero.com/RADStudi ... id_Support
Lena
BCBJ Master
BCBJ Master
 
Posts: 623
Joined: Sun Feb 06, 2011 1:28 pm

Re: Firebase Android Support C++ code?

Postby rlebeau » Tue Jul 23, 2019 2:42 pm

Something like this:

Code: Select all
#include <FMX.PushNotification.Android.hpp>

...

class TFormMain : public TForm
{
__published:
    TMemo *MemoLog;
    ...
private:
    String FDeviceId;
    String FDeviceToken;
    ...
    void __fastcall OnServiceConnectionChange(TObject* Sender, TPushService::TChanges PushChanges);
    void __fastcall OnReceiveNotificationEvent(TObject* Sender, TPushServiceNotification* const ANotification);
    ...
public:
    __fastcall TFormMain(TComponent *Owner);
    ...
};

...

__fastcall TFormMain::TFormMain(TComponent *Owner)
    : TForm(Owner)
{
    TPushService *PushService = TPushServiceManager::Instance->GetServiceByName(TPushService_TServiceNames_GCM);

    TPushServiceConnection *ServiceConnection = new TPushServiceConnection(PushService);
    ServiceConnection->Active = true;
    ServiceConnection->OnChange = &OnServiceConnectionChange;
    ServiceConnection->OnReceiveNotification = &OnReceiveNotificationEvent;
 
    FDeviceId = PushService->DeviceIDValue[TPushService_TDeviceIDNames_DeviceID];
    MemoLog->Lines->Add(_D("DeviceID: ") + FDeviceId);
    MemoLog->Lines->Add(_D("Ready to receive!"));
 
    // Checks notification on startup, if application was launched from cold start
    // by tapping on Notification in Notification Center
    DynamicArray<TPushServiceNotification*> Notifications = PushService->StartupNotifications;
    if (Notifications.Length > 0)
    {
        MemoLog->Lines->Add(_D("-----------------------------------------");
        MemoLog->Lines->Add(_D("DataKey = ") + Notifications[0]->DataKey);
        MemoLog->Lines->Add(_D("Json = ") + Notifications[0]->Json->ToString());
        MemoLog->Lines->Add(_D("DataObject = ") + Notifications[0]->DataObject->ToString());
        MemoLog->Lines->Add(_D("-----------------------------------------"));

        // alternatively:
        // for(TPushServiceNotification* notification : Notifications)
        //     OnReceiveNotificationEvent(nullptr, notification);
    }
}

void __fastcall TFormMain::OnServiceConnectionChange(TObject* Sender, TPushService::TChanges PushChanges)
{
    TPushService *PushService = TPushServiceManager::Instance->GetServiceByName(TPushService_TServiceNames_GCM);

    if (PushChanges.Contains(TPushService::TChange::DeviceToken))
    {
        FDeviceToken = PushService->DeviceTokenValue[TPushService_TDeviceTokenNames_DeviceToken];
        MemoLog->Lines->Add(_D("FireBase Token: ") + FDeviceToken);
        Log::d(_D("Firebase device token: token=") + FDeviceToken);
    }

    if (PushChanges.Contains(TPushService::TChange::Status) && PushService->Status.Contains(TPushService::TStatus::StartupError))
        MemoLog->Lines->Add(_D("Error: ") + PushService->StartupError);
}

void __fastcall TFormMain::OnReceiveNotificationEvent(TObject* Sender, TPushServiceNotification* const ANotification)
{
    MemoLog->Lines->Add(_D("-----------------------------------------"));
    MemoLog->Lines->Add(_D("DataKey = ") + ServiceNotification->DataKey);
    MemoLog->Lines->Add(_D("Json = ") + ServiceNotification->Json->ToString());
    MemoLog->Lines->Add(_D("DataObject = ") + ServiceNotification->DataObject->ToString());
    MemoLog->Lines->Add(_D("---------------------------------------"));
}
Remy Lebeau (TeamB)
Lebeau Software
User avatar
rlebeau
BCBJ Author
BCBJ Author
 
Posts: 1606
Joined: Wed Jun 01, 2005 3:21 am
Location: California, USA

Re: Firebase Android Support C++ code?

Postby Lena » Wed Jul 24, 2019 2:44 am

Thank You very much for Your help!

Please tell me where I will see this entry:
Log::d(_D("Firebase device token: token=") + FDeviceToken);
Lena
BCBJ Master
BCBJ Master
 
Posts: 623
Joined: Sun Feb 06, 2011 1:28 pm

Re: Firebase Android Support C++ code?

Postby rlebeau » Wed Jul 24, 2019 12:34 pm

Lena wrote:Please tell me where I will see this entry:
Log::d(_D("Firebase device token: token=") + FDeviceToken);


Per http://docwiki.embarcadero.com/Libraries/en/FMX.Types.Log.d:

Displays a message in the Event Log.


IOW, in the IDE's own Events window.
Remy Lebeau (TeamB)
Lebeau Software
User avatar
rlebeau
BCBJ Author
BCBJ Author
 
Posts: 1606
Joined: Wed Jun 01, 2005 3:21 am
Location: California, USA

Re: Firebase Android Support C++ code?

Postby Lena » Thu Jul 25, 2019 3:01 am

Thank You very much!
Lena
BCBJ Master
BCBJ Master
 
Posts: 623
Joined: Sun Feb 06, 2011 1:28 pm


Return to Technical

Who is online

Users browsing this forum: No registered users and 16 guests