question

Nima Bagheri avatar image
Nima Bagheri asked

[UE4] Andriod device push notification registration failed

I have set up push notification in PlayFab successfully however I can't figure out how to register for (Android) notifications in unreal engine. I am a bit surprised that there is very little documentation on UE4 but there are plenty on Unity. I am confident there is no issue with notification setup on PlayFab side. By referring to Unity example I figured out, first you need to log in with Android device and then call the Android Device Push Notification Registration Node. It would be nice to know what paremeters are optional and what are required. Also what is Device Token?

1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

element808 avatar image element808 commented ·

When I get back to my PC, I'll give you some screenshots of how I implemented it. There is one C++ function you'll need to add to convert the Array of Bytes (Device Token) to String, but I'll provide you with my source code for it.

1 Like 1 ·
element808 avatar image
element808 answered

@Nima Bagheri - as promised, here's our implementation of it.

The first thing we did was bind to the Application Registered for Remote Notifications Delegate in blueprints. This gets triggered when a user accepts the remote notification request for permission prompt.The "In Array" output of this delegate is your device token. However, since the output is an array of bytes, you have to add a C++ function that is blueprintable to convert this value for you.


The source code we used, and added to our game helper class, was the following (replace UHuliHelper with the name of your custom class file):

Header:

UFUNCTION(BlueprintCallable, Category = "HuliHelper | Conversions | Byte to String")
static FString BytesToStringFixed(const TArray<uint8> &InByteArray);

CPP:

FString UHuliHelper::BytesToStringFixed(const TArray<uint8> &InByteArray)
{
	//Create string from byte array
	const std::string cstr(reinterpret_cast<const char*>(InByteArray.GetData()), InByteArray.Num());
	return FString(cstr.c_str());
}

Lastly, we added a custom event for completing the Remote Push Notification process on the PlayFab side of things:

Hope this helps. If you have anymore questions, let me know.


1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

yusuke avatar image yusuke commented ·

Hello.

Looking at this comment, I was able to form a node as in the photo.

It succeeded on Android and succeeded in getting a device token and sending a push notification.

But with IOS this doesn't succeed for some reason.

The bound event is never called when RegisterRemoteNotifications is executed.

So I can't get the iOS device token.

Has the fix for this issue in the engine source been resolved?

It's very troubled.Help me.

0 Likes 0 ·
Sarah Zhang avatar image
Sarah Zhang answered

According to the API reference of AndroidDevicePushNotificationRegistration, ConfirmationMessage, SendPushNotificationConfirmation are optional, DeviceToken is required. DeviceToken is the registration ID provided by the FCM service when the title registered to receive push notifications. You can navigate to the FCM’s Set up a C++ client documentation especially the section Access the device registration token for more information about it. To register a device in Unreal, you may need to follow the above C++ documentation to get the device token or you can try to search the corresponding blueprints plugin in the Unreal Marketplace.

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Nima Bagheri avatar image
Nima Bagheri answered

@Element808
Thank you very much for the implementation!!! I really appreciate it.
Currently I have problem with the delegate as there is no call back. I am calling the BindApplicationRegisteredForRemoteNotificationsDelegate function after the player has successfully login to playfab. Am I missing a configuration?

1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

element808 avatar image element808 commented ·

That's fine to put it there, just as long as it's not on an event tick, it's somewhere prior to it being needed, and on something that does not get garbage collected; such as UMG UI's that are not persistent because as soon as the asset is no longer needed the bind and implementation goes with it. We put ours in the GameInstance because it never goes away and acts as a singleton.

Also, make sure you have called the UE4 blueprint function that generates the request for push notifications (Register for Remote Notifications is the node) AFTER you have set your bind. Remember, the delegate will only get called when a player accepts push notifications from your game via this Register for Remote Notifications node.

Lastly, make sure that your project settings have push notifications enabled under Android section, and that you're testing it on an Android mobile device as none of the Play In Editor modes simulate any of this functionality.

0 Likes 0 ·
Nima Bagheri avatar image
Nima Bagheri answered

@element808 I think I know what is the problem, I never get prompt to accept notifications. Do I need to do something specific to get that? Also I cant find enabling notification on android settings, I see one for ios but not android.

1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

element808 avatar image element808 commented ·

My mistake :) forgot Android doesn't have that checkbox for allowing remote notifications. Try something for me: go into your app settings on your Android device for your game, and manually allow notifications then try to start up your game again...can set up multiple print strings to see how far in the workflow your game gets to help troubleshoot. I'm currently away from my PC, so I'm assisting from memory lol

0 Likes 0 ·
Nima Bagheri avatar image
Nima Bagheri answered

@Element808
I am using Samsung Galaxy J3 Pro - Android version 9 (Pie) I have attached screenshots of my setup Here is the adb log: 06-25 13:13:28.024 12213 12467 D UE4 : [2020.06.25-10.13.28:023][377]LogBlueprintUserMessages: [GI_PlatformMain_C_2147482610] Login Success 06-25 13:13:28.025 12213 12467 D UE4 : [2020.06.25-10.13.28:025][377]LogSlate: Updating window title bar state: overlay mode, drag disabled, window buttons hidden, title bar hidden 06-25 13:13:28.025 12213 12467 D UE4 : [2020.06.25-10.13.28:025][377]LogUMG: Display: Widget Class WBP_Details_C - Loaded Fast Template. 06-25 13:13:28.028 12213 12467 D UE4 : [2020.06.25-10.13.28:028][377]LogBlueprintUserMessages: [GI_PlatformMain_C_2147482610] Bound event to application received remote notification delegate 06-25 13:13:29.977 12213 12467 D UE4 : [2020.06.25-10.13.29:977][406]LogBlueprintUserMessages: [GI_PlatformMain_C_2147482610] Register for remote notification node just called 06-25 13:13:36.370 12213 12470 D UE4 : Used memory: 180701 06-25 13:13:46.652 12213 12470 D UE4 : Used memory: 179384 06-25 13:13:56.955 12213 12470 D UE4 : Used memory: 179422 06-25 13:14:07.224 12213 12470 D UE4 : Used memory: 179552 06-25 13:14:17.496 12213 12470 D UE4 : Used memory: 179660 06-25 13:14:27.775 12213 12470 D UE4 : Used memory: 180064 06-25 13:14:38.046 12213 12470 D UE4 : Used memory: 180139 06-25 13:14:48.345 12213 12470 D UE4 : Used memory: 180018 06-25 13:14:58.614 12213 12470 D UE4 : Used memory: 179978 06-25 13:15:08.922 12213 12470 D UE4 : Used memory: 179847 06-25 13:15:19.188 12213 12470 D UE4 : Used memory: 179935 06-25 13:15:29.453 12213 12470 D UE4 : Used memory: 180139 06-25 13:15:39.714 12213 12470 D UE4 : Used memory: 180299 06-25 13:15:49.984 12213 12470 D UE4 : Used memory: 180383 06-25 13:16:00.281 12213 12470 D UE4 : Used memory: 180177 06-25 13:16:10.549 12213 12470 D UE4 : Used memory: 180445 06-25 13:16:20.840 12213 12470 D UE4 : Used memory: 180409 06-25 13:16:31.111 12213 12470 D UE4 : Used memory: 179290 06-25 13:16:41.376 12213 12470 D UE4 : Used memory: 179162 06-25 13:16:51.649 12213 12470 D UE4 : Used memory: 179238 06-25 13:17:01.921 12213 12470 D UE4 : Used memory: 179526 06-25 13:17:12.212 12213 12470 D UE4 : Used memory: 179616 06-25 13:17:22.490 12213 12470 D UE4 : Used memory: 179680 06-25 13:17:32.794 12213 12470 D UE4 : Used memory: 179760 06-25 13:17:43.068 12213 12470 D UE4 : Used memory: 179764 06-25 13:17:53.371 12213 12470 D UE4 : Used memory: 179912 06-25 13:17:57.512 12213 12213 D UE4 : Battery: status = 2, rawlevel = 100, scale = 100 06-25 13:17:57.512 12213 12213 D UE4 : nativeBatteryEvent(stat = 2, lvl = 100 temp = 28.50 ┬░C) 06-25 13:18:03.639 12213 12470 D UE4 : Used memory: 179848 06-25 13:18:13.904 12213 12470 D UE4 : Used memory: 179932 06-25 13:18:24.177 12213 12470 D UE4 : Used memory: 180104 06-25 13:18:34.460 12213 12470 D UE4 : Used memory: 180252 06-25 13:18:44.740 12213 12470 D UE4 : Used memory: 180328 06-25 13:18:55.014 12213 12470 D UE4 : Used memory: 180412 06-25 13:19:05.321 12213 12470 D UE4 : Used memory: 180612 06-25 13:19:15.594 12213 12470 D UE4 : Used memory: 180776 06-25 13:19:25.887 12213 12470 D UE4 : Used memory: 179324 06-25 13:19:36.164 12213 12470 D UE4 : Used memory: 179472 06-25 13:19:46.431 12213 12470 D UE4 : Used memory: 179537 06-25 13:19:47.962 12213 12213 D UE4 : Battery: status = 2, rawlevel = 100, scale = 100 06-25 13:19:47.962 12213 12213 D UE4 : nativeBatteryEvent(stat = 2, lvl = 100 temp = 28.60 ┬░C) 06-25 13:19:56.709 12213 12470 D UE4 : Used memory: 179341 06-25 13:20:06.992 12213 12470 D UE4 : Used memory: 180187 06-25 13:20:17.296 12213 12470 D UE4 : Used memory: 179778 06-25 13:20:27.570 12213 12470 D UE4 : Used memory: 179726 06-25 13:20:37.871 12213 12470 D UE4 : Used memory: 179949 06-25 13:20:48.145 12213 12470 D UE4 : Used memory: 179886 06-25 13:20:48.204 12213 12213 D UE4 : Battery: status = 2, rawlevel = 100, scale = 100 06-25 13:20:48.204 12213 12213 D UE4 : nativeBatteryEvent(stat = 2, lvl = 100 temp = 28.70 ┬░C) 06-25 13:20:58.421 12213 12470 D UE4 : Used memory: 179962 06-25 13:21:08.696 12213 12470 D UE4 : Used memory: 178686 06-25 13:21:18.977 12213 12470 D UE4 : Used memory: 180298 06-25 13:21:29.246 12213 12470 D UE4 : Used memory: 180446 06-25 13:21:39.513 12213 12470 D UE4 : Used memory: 180462 06-25 13:21:49.805 12213 12470 D UE4 : Used memory: 180202 06-25 13:22:00.085 12213 12470 D UE4 : Used memory: 180402 06-25 13:22:08.535 12213 12213 D UE4 : Battery: status = 2, rawlevel = 100, scale = 100 06-25 13:22:08.535 12213 12213 D UE4 : nativeBatteryEvent(stat = 2, lvl = 100 temp = 28.80 ┬░C) 06-25 13:22:10.411 12213 12470 D UE4 : Used memory: 180689

screenshot-1.png (145.6 KiB)
screenshot-2.png (67.9 KiB)
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Nima Bagheri avatar image
Nima Bagheri answered

I've found what was the problem with the delegate call back, I had to add the firebase sender ID to UE4 google cloud messaging sender ID in the project settings

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

yusuke avatar image
yusuke answered

Hello.

Looking at this comment, I was able to form a node as in the photo.

It succeeded on Android and succeeded in getting a device token and sending a push notification.

But with IOS this doesn't succeed for some reason.

The bound event is never called when RegisterRemoteNotifications is executed.

So I can't get the iOS device token.

Has the fix for this issue in the engine source been resolved?

It's very troubled.Help me.

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.