Page 1 of 1

Firebase Android Support C++ code?

PostPosted: Tue Jul 23, 2019 2:34 am
by Lena
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

Re: Firebase Android Support C++ code?

PostPosted: Tue Jul 23, 2019 2:42 pm
by rlebeau
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("---------------------------------------"));
}

Re: Firebase Android Support C++ code?

PostPosted: Wed Jul 24, 2019 2:44 am
by Lena
Thank You very much for Your help!

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

Re: Firebase Android Support C++ code?

PostPosted: Wed Jul 24, 2019 12:34 pm
by rlebeau
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.

Re: Firebase Android Support C++ code?

PostPosted: Thu Jul 25, 2019 3:01 am
by Lena
Thank You very much!

Re: Firebase Android Support C++ code?

PostPosted: Thu Oct 31, 2019 1:17 am
by Sparow
rlebeau wrote:
Lena wrote:Please tell me where I will see this entry:
Log::d(_D("Firebase device token: token=") + FDeviceToken);


@rlebeau: In article http://docwiki.embarcadero.com/RADStudi ... id_Support I see "Services" in Project Options dialog. It allows developer to import google-services.json. However in my 10.3.2 C++ Builder Community I don't see such item, so I have no idea how to import google-services.json.
For now my app crashes at startup with error java.lang.RuntimeException: Unable to get provider com.embarcadero.firebase.provider.FirebaseInitProvider: java.lang.IllegalStateException: ApplicationId must be set, I suspect the json must be imported first.
Pls give me some clues, thank you very much.

Re: Firebase Android Support C++ code?

PostPosted: Thu Oct 31, 2019 10:45 am
by Lena

Re: Firebase Android Support C++ code?

PostPosted: Thu Oct 31, 2019 7:29 pm
by Sparow
Yes you're correct, thanks @Lena. This is a bug.
I'm about to ditch C++ Builder for good. I started with C++ Builder 3 months ago, nearly completed multi-device app, but now I'm thinking about rewriting everything in native. FMX idea is excellent, but implementation is worse of the worse. Now I cannot even publish Android app to Play Store due to lack of 64bit support.
@Lena: I have a question: do you have any serious problem with C++ Builder multi-device apps (beside no 64 bit Android)? Thanks again.

Re: Firebase Android Support C++ code?

PostPosted: Fri Nov 01, 2019 4:05 pm
by rlebeau
Sparow wrote:I'm about to ditch C++ Builder for good. I started with C++ Builder 3 months ago, nearly completed multi-device app, but now I'm thinking about rewriting everything in native. FMX idea is excellent, but implementation is worse of the worse.


Yeah, I'm not a big fan of FMX, either. But I use C++Builder only for Windows development, and VCL rocks for that platform.

Sparow wrote:Now I cannot even publish Android app to Play Store due to lack of 64bit support.


C++Builder support for 64-bit Android is not going to be available until at least mid-2020. Delphi support for 64-bit Android is currently in beta, though. If you had an existing 32-bit app in the Play Store before the August 1 2019 deadline, you can request an extension from Google to continue posting updates to that 32-bit app until August 2020 without adding 64-bit support. But after August 2020, 64-bit is a MUST, hopefully C++Builder will be ready by then.