question

Lukasz Borun avatar image
Lukasz Borun asked

Problem with Android Push Register

Hi, 

I have problem with register device for token. I successful configured iOS and Android APN. When i want to register a device with that code:

PlayFabGoogleCloudMessaging._RegistrationReadyCallback += RegistrationReadyCallback;
PlayFabGoogleCloudMessaging._RegistrationCallback += RegistrationCallback;
PlayFabGoogleCloudMessaging._MessageCallback += OnPushReceived;
PlayFabAndroidPlugin.Init(sender_id);

the event _RegistrationReadyCallback never callback. 

I use latest PlayFabSDK for Unity3D

Ps. There are only logs for GCM:
03-25 14:28:45.570: I/PlayFabUAP(18917): PlayFab GCM Init, saving prefs.
03-25 14:28:45.570: I/PlayFabUAP(18917): Setting SenderId: xxxxxxxxx (my sender_id)
03-25 14:28:45.570: I/PlayFabUAP(18917): PlayFabUnityAndroidPlugin Service, Binding to Unity Activity


Thanks.

10 |1200

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

Zac Bragg avatar image
Zac Bragg Deactivated answered

All,

We rebuilt our Unity Android Push Notification Plugin. This is no longer 'installed' by default; developers will need to selectively import the AssetPackage; which can be found  here.

 

Thanks,

Zac

10 |1200

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

bda2206@gmail.com avatar image
bda2206@gmail.com answered

I think I'm getting similar lack of result in xamarin..

10 |1200

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

Lukasz Borun avatar image
Lukasz Borun answered

Anyone? This is very important feature in our game :/

10 |1200

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

brendan avatar image
brendan answered

Apologies for the delay on this - I've asked the tools team to review and respond ASAP.

10 |1200

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

Lukasz Borun avatar image
Lukasz Borun answered

@Brendan any progress of this? Today I removed all other plugins and I had the same result :/

10 |1200

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

1807605288 avatar image
1807605288 answered

It is unclear to me if this is a code issue, or a sequence of events issue.  It's also unclear which API calls you are making and in what order, so I'm going to list out the full process here:

There's multiple apis that must be called in order to receive a push notification, even if your plugin is set up correctly.

1. You must set up push notifications on your title:
https://api.playfab.com/Documentation/Admin/method/SetupPushNotification
2. Your client must log in every time the game starts:
https://api.playfab.com/Documentation/Client/method/LoginWithAndroidDeviceID
 - or -
(or any other login call plus:) https://api.playfab.com/Documentation/Client/method/LinkAndroidDeviceID
3. At some point, the client must call to activate push notifications:
https://api.playfab.com/Documentation/Client/method/AndroidDevicePushNotificationRegistration (after login, only call once)
4. The server must send a push notification directly to the specific client (via PlayFabId - once for each push notification)
https://api.playfab.com/Documentation/Server/method/SendPushNotification

If you fail to call #1, then you can't send push notifications.  If you fail to call #3, then the client won't receive push notifications.  You can double check #3 in Game Manager when you view a specific player(insert your values first): https://developer.playfab.com/en-us/{ {Your-titleId}}/players/{ {Your-playFabId}}/overview

(You can get to this url directly by clicking on the PlayStream login event, as your player logs in)

The "Push enabled" value should be true.  If it is false, you have not completed step 3.

We have a guide for Push Notifications here which covers various steps and issues:
https://api.playfab.com/docs/push-basics
https://api.playfab.com/docs/push-for-android

Lastly, in Unity, there's a deeply nested setting:
Edit -> Project Settings -> Player (views player settings into the inspector)Android (icon) -> Identification -> Bundle Identifier
This must be set to the correct value according to your app in the google store.
(bda2206: There is likely a similar setting in Xamarin)

Please check all of those things first.  Make sure all of the api calls listed have been called with appropriate values.

10 |1200

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

Lukasz Borun avatar image
Lukasz Borun answered



Uhm... Before i can send a push to any devices i need to get them DeviceToken and register it. Right?. But I can't get that token because  PlayFabGoogleCloudMessaging._RegistrationReadyCallback never callback after I execute PlayFabAndroidPlugin.Init(senderId) (always Push enabled is false). I successful configure push for androdi na ios.

User is login to application using LoginWithFacebook but i never used LinkAndroidDeviceID
 

10 |1200

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

Zac Bragg avatar image
Zac Bragg Deactivated answered

Hey Lukasz,

Can you post your complete plugin initialization code as well as your device details (OS, Model, etc). And please confirm that you are not using any Unity plugins that may conflict with any portion of the GCM API.

 

Thanks,

Zac

10 |1200

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

Lukasz Borun avatar image
Lukasz Borun answered

Hi Zac!

I created a new project. (No additional plugins, only PlayFabSDK). Here is my script for GCM:

using UnityEngine;
using PlayFab;
using PlayFab.ClientModels;


public class NotificationTest : MonoBehaviour {

// Use this for initialization
void Start ()
{
PlayFabSettings.TitleId = TitleId;

PlayFabClientAPI.LoginWithAndroidDeviceID(new LoginWithAndroidDeviceIDRequest()
{
AndroidDevice = SystemInfo.deviceModel,
OS = SystemInfo.operatingSystem,
AndroidDeviceId = SystemInfo.deviceUniqueIdentifier,
CreateAccount = true
}, ResultCallback, ErrorCallback);


}

private void ErrorCallback(PlayFabError error)
{
Debug.Log("ERROR LOGIN");
}

private void ResultCallback(LoginResult result)
{
Register();
}

private void Register()
{
Debug.Log("init Notification");
PlayFabGoogleCloudMessaging._RegistrationReadyCallback += RegistrationReadyCallback;
PlayFabGoogleCloudMessaging._RegistrationCallback += RegistrationCallback;
PlayFabAndroidPlugin.Init(SenderId);
}

private void RegistrationReadyCallback(bool status)
{
Debug.Log("RegistrationReadyCallback Status" + status);

PlayFabGoogleCloudMessaging.GetToken();
}

private void RegistrationCallback(string id, string error)
{
Debug.Log("Token: " + id + " error:" + error);
}


}

Unfortunately i got the same result.  _RegistrationReadyCallback never callback. User was successful logged to PlayFab. 

I testet on Huawei P8 5.0.1 and Samsung Galaxy S4 5.0.1 

ps. I Downloaded a example notification for Your GitHub project. I have te same result. "UNREGISTERED" in right-bottom of screen. Next i installed a new plugin UltimateMobile. With that plugin i have successful got DeviceToken and with PlayFabAPI registered it. Next  I send push notification from PlayFabAPI (using postman). In Log I saw a message I sent. My app seems to be good configured.


Thank you for your time. 

10 |1200

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

Zac Bragg avatar image
Zac Bragg Deactivated answered

Lukasz,

Thanks for the code. I have a few suggestions / clarifying questions:

  1. Can you confirm that you are properly setting SenderId in the call: PlayFabAndroidPlugin.Init(SenderId); I do not see this value being set, and suspect that this could be an issue.
  2. Make your event registration calls & Init() earlier in the application; OnEnable() & OnDisable are good monobehavior locations to bind and unbind to the event.
  3. Regarding this push example, you mention that it says "Unregistered", is this after you add your own google sender id and click the register button down below? If possible send me the logcat or unity console output when running this application on a device. 
  4. Lastly, all you need is the push device token, so if you are able to get that via other plugins you can provide the token to our API call and you should be registered for push notifications. Be aware the plugins usually control / override how the push messages are handled, so you should keep that in mind for how you will want the push message to behave in your final version.

Hope this gets you unblocked,

Zac

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.