Device Registration from Unity

Hey!

I’m in a dire need of assistance after banging my head against a wall for a couple of days. We need to register an Android device in Backendless via C# code and be able to send some push notifications from server-code to the device. All else is clear, but we haven’t yet been able to successfully register a device on BE. We’d like to hear your opinions about the best way to approach this.

Here’s what we have tried:

  1. using REST API. Device appears in the Backendless for a while (at least until I try to send a push to it) and then disappears. I understand the deviceToken field is something that we haven’t been able to figure out. It is supposed to be the one obtained by Google Play Services plugin, right? Well the problem is I don’t know a way to get the plugin to Unity, since it practically requires AndroidStudio to obtain.

  2. using (unofficial) Backendless plugin for Unity. Well this one just didn’t work. Although many other functions in it are very useful, but RegisterDevice() throws object reference -error.

  3. using Backendless Android API. I downloaded the API and moved the built .jar library into Unity’s plugin folder. From Unity I’m able to call “registerDevice()” -function without error messages, but the device still never shows up in Backendless. Under is some reference code I wrote trying to use Android API. I also tried to Initialize the app before calling registerDevice(), but it made no difference.

AndroidJavaClass cls_jni = new AndroidJavaClass("com.backendless.Messaging");
using (AndroidJavaClass cls_UnityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer"))
{
        using (AndroidJavaObject obj_Activity = cls_UnityPlayer.GetStatic<AndroidJavaObject>    ("currentActivity"))
            {

                Debug.Log("Calling Backendless registerDevice()");

                object[] args = { GCM_ID };
                cls_jni.Call("registerDevice", args);

                Debug.Log("Device registrated!");
                
            }

        }

Worry not! I have found a solution for this particularly itchy problem:

I implemented only a part of Google Play Services (“play_services_gcm” -lib). Then I copied a .jar inside that lib into Unity plugins and called the DeviceID java class from C#. I got the token (which is long as all hell btw) and registered device using REST. Pushes work like a charm. I can add more information or sample code if you’re struggling with the same problem, stranger reading this. For now, this case can be closed. Sorry if you already looked into this in vain, Backendless staff. Thanks.

-Larri