I've tested this multiple times on an example project / plugin, and it seems to work perfectly. Once I begin integration on my actual project, I get an error (seen below). I've lost about two weeks trying to get Unity / Android plugins working, and this is the furthest I've gotten. I feel so close, but so far from finding the solution! Any help I can get is greatly appreciated. Thank you!
The error that I'm getting:
08-28 15:38:25.200: I/Unity(6191): AndroidJavaException: java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
C# (Unity):
// Update is called once per frame
void Update () {
testPlugin ();
printTestobj();
}
public void testPlugin() {
if (testobj == null) {
// First, obtain the current activity context
using (var actClass = new AndroidJavaClass("com.unity3d.player.UnityPlayer")) {
playerActivityContext = actClass.GetStatic<AndroidJavaObject> ("currentActivity");
}
// Pass the context to a newly instantiated TestUnityProxy object
using (var pluginClass = new AndroidJavaClass("com.company.product.Main")) {
if (pluginClass != null) {
testobj = pluginClass.CallStatic<AndroidJavaObject> ("instance");
testobj.Call ("setContext", playerActivityContext);
}
}
}
}
Java (Android):
public Main() {
INSTANCE = this;
}
public static Main instance() {
Log.i(TAG, "Inside instance.");
if (INSTANCE == null) {
Log.i(TAG, "instance b1.");
INSTANCE = new Main();
Log.i(TAG, "instance b2.");
}
Log.i(TAG, "instance b3.");
return INSTANCE;
}
public void setContext(Context ctx) {
this.context = ctx;
Log.i(TAG, "Application context set.");
}
Looper.prepare()at the beginning of the thread's job (Runnable, AsyncTask, etc). - mstrthealias