question

andreasumbricht avatar image
andreasumbricht asked

PushDebuggerProject OnGCMReady is never called

Hello there

I want to set up push notifications for my game.

I made a google developer project.

After that I created a server-api key and a google cloud message api key.

I linked the google cloud message api key with my app inside the google play developer console.

After checking if everything works fine (https://api.playfab.com/Documentation/Admin/method/SetupPushNotification with a 200 response), I linked the server api key within playfab, so android push notifications are enabled.

I installed the newest versions of the PlayFabClientSDK.unitypackage and also the AndroidPushPlugin.unitypackage.

Then i downloaded the PushDebuggerProject (https://github.com/PlayFab/PlayFab-Samples/tree/master/TestingTools/PushNotifications) and followed the README.

After inserting the TitleId and the Google project id from my google developer project i wanted to run the application.

The scenes starts fine, without any crashes and the console says:

I/Unity   ( 8311): Starting Auto-login Process

I/Unity   ( 8311): Making Request Using WWW

I/Unity   ( 8311): /Client/LoginWithAndroidDeviceID

I/Unity   ( 8311): https://**HERE IS MY TITLE ID**.playfabapi.com/Client/LoginWithAndroidDeviceID

I/Unity   ( 8311): {"TitleId":"**HERE IS MY TITLE ID**","AndroidDeviceId":"ee88d1bfb8e9a0ecab0cd8e012140cdd","OS":"Android OS 5.1.1 / API-22 (LMY47X/N915FYXXU1COJ2)","AndroidDevice":"samsung SM-N915FY","CreateAccount":true}

I/Unity   ( 8311): SenderID: escoba-push-notifications

I/Unity   ( 8311): Createding new _PLayFabGO

I/Unity   ( 8311): On Device: ee88d1bfb8e9a0ecab0cd8e012140cd

I/Unity   ( 8311): PlayFab Authentication Successful! -- Player ID:AFFD928FF8834AB6  

After pressing the "registration" button, the console says that:

Push Token was null or empty: 

So I had a debug session and after that I noticed that the function OnGCMReady is never called, which is used to get the token.

Can anyone of you guess what I did wrong?

Kind regards

Andreas

Push Notifications
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

How are you getting the DeviceToken that you pass into the call to https://api.playfab.com/Documentation/Client/method/AndroidDevicePushNotificationRegistration?

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.

andreasumbricht avatar image andreasumbricht commented ·

According to this guide (https://api.playfab.com/docs/push-for-android), I call PlayFabGoogleCloudMessaging.GetToken() in the OnGCMReady function.

public static void OnGCMReady(bool status){
	if(status == true){
		Debug.Log("GCM Plugin Ready!");
		PlayFabGoogleCloudMessaging.GetToken();
	}else{
		Debug.Log("Error: GCM is unavailable.");
	}
}

As far as I know, this function will be called after PlayFabAndroidPlugin.Init() is finished. However in my case it is never called, without any error output.

So I never really get the token, and I never get to call AndroidDevicePushNotificationRegsitration.

0 Likes 0 ·
Zac Bragg avatar image
Zac Bragg Deactivated answered

Hello Andreas,

I have been pointing people to use the 4.7 plugin until the updated 5.x versions is ready for release.

The 5.x plugin should be ready soon. I will ask Marco for an ETA.

-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.

andreasumbricht avatar image
andreasumbricht answered

@Zac Bragg @Brendan

I am alreday using the 4.7 plugin.

Here is my full code:

using UnityEngine;

using System.Collections;

using PlayFab;

using PlayFab.ClientModels;



public class android_controller : MonoBehaviour {

    private string titleId = "****";

    private string playerPlayFabId;

    private string GoogleProjectId = "************";



    void Start () {

        this.login();

    }



    private void login(){

        PlayFabSettings.TitleId = this.titleId;



        LoginWithCustomIDRequest request = new LoginWithCustomIDRequest(){

            CreateAccount = true,

            CustomId = SystemInfo.deviceUniqueIdentifier

        };



        PlayFabClientAPI.LoginWithCustomID(request, (result) => {

            this.playerPlayFabId = result.PlayFabId;

            this.getCloudURL();

        },(error) => {

            Debug.Log(error);

        });

    }



    private void getCloudURL(){

        GetCloudScriptUrlRequest request = new GetCloudScriptUrlRequest() {

            Testing = false

        };



        PlayFabClientAPI.GetCloudScriptUrl(request, (result) => {

            this.registerForPushNotification();

        },(error) => {

            Debug.Log(error.ErrorMessage);

        });

    }



    private void registerForPushNotification(){

        if(!string.IsNullOrEmpty(this.GoogleProjectId)){

            PlayFabGoogleCloudMessaging._RegistrationReadyCallback += OnGCMReady;

            PlayFabGoogleCloudMessaging._RegistrationCallback += OnGCMRegistration;

            PlayFabGoogleCloudMessaging._MessageCallback += OnMessageReceived;



            PlayFabAndroidPlugin.Init(this.GoogleProjectId);

        }

    }



    public void OnGCMReady(bool status){

        Debug.Log (status);

        Debug.Log ("INIT FINISHED");

        PlayFabGoogleCloudMessaging.GetToken ();

    }



    public void OnGCMRegistration(string id, string error){

        //DO REGISTRATION HERE

    }



    public void OnMessageReceived(string message){

        Debug.Log (message);

    }

}

The problem is still my PlayFabAndroidPlugin.Init() function.

It doesn't create a callback, so I am never able to get my device token.

When I debugged the code I found out, that the code is running up until here:

public static void Init(){
	PlayFabGCMClass = new AndroidJavaClass("com.playfab.unityplugin.GCM.PlayFabGoogleCloudMessaging");
        PlayFabPushCacheClass = new AndroidJavaClass("com.playfab.unityplugin.GCM.PlayFabPushCache");
}

This. function is located at PlayFabAndroid.cs line 89;

After that, no function is called.

I don't really know I possibly could do wrong.

Is the google project id an only numeric string with 12 lettres or is it like "my-test-game"?

I tried both, nothing works, but just to be sure.

Kind regards

Andreas

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

No this is likely our Plugin not working correctly on your particular device. I am hoping to have our new plugin out this week. Stay tuned, I will post back here when we release.

Sorry for the inconvience,

-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.

Zac Bragg avatar image
Zac Bragg Deactivated answered

Hello Andreas,

We recently rebuilt our Android Unity Push Plugin.

This can be found over here; with full source & documentation here.

Let us know if you find any issues.

-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.