- Home /
Events not fired in Android Plugin
Android function not fired
Hi all,
I'm working on an Android Project on Unity and I am trying to use a Java SDK to manage Estimote beacons. I created an Android Lib on Android Studio and imported it in Unity. Unfortunately, my "onBeaconsDiscovered" is never fired..
Here is the code of my Android Library:
public class Helper {
BeaconManager _m=null;
public static void DoSthInAndroid()
{
Log.i("Unity", "Hi from Android");
}
public void setRangingMethodToManager(UnityPlayerNativeActivity c) throws InterruptedException {
Log.d("Unity","TOUT AVANT");
_m=new BeaconManager(c);
Log.d("Unity","UN PEU APRES");
_m.setRangingListener(new BeaconManager.RangingListener() {
@Override
public void onBeaconsDiscovered(Region region, List<Beacon> list) {
Log.d("nouvelle balise !","new beacon discovered");
}
});
Log.d("nouvelle balise !","APRES");
}
}
I've compiled this code in Android Studio, and pasted the "classes.jar" created in Android/Plugin. Here is the way i used it on Unity :
using System.Collections; using System.Collections.Generic; using UnityEngine; public class NewBehaviourScript : MonoBehaviour {
public AndroidJavaObject jo;
public AndroidJavaObject jo2;
public static AndroidJavaClass myClass2;
public static AndroidJavaClass myClass3;
public AndroidJavaClass androidJC;
void Start()
{
init();
}
public void init()
{
this.androidJC= new AndroidJavaClass("com.unity3d.player.UnityPlayer");
this.jo = androidJC.GetStatic<AndroidJavaObject>("currentActivity");
this.jo2 = new AndroidJavaObject("com.example.r_boug.myunitylib.Helper");
// Calling a Call method to which the current activity is passed
this.jo2.CallStatic("DoSthInAndroid");
this.jo2.Call("setRangingMethodToManager", this.jo);
this.jo2.CallStatic("DoSthInAndroid");
// Debug.Log("apres");
}
void OnGUI()
{
// init();
if (GUI.Button(new Rect(10, 200, 150, 120), "SHOW INTENT"))
{
myClass2.CallStatic("DoSthInAndroid");
this.jo.CallStatic("logOK");
}
}
}
My code is working and the "setRangingMethodToManager" function is fired, but I do not receive any display of "new beacon discovered". The code before and after this is executed(i can read the logs), but it seems as if events are not fired.. did I do something wrong ?
Thanks for your help !
Your answer
