Hey everybody. So, I have a java class, as such:
package com.example.test;
import android.app.Activity;
import android.os.Bundle;
public class test extends Activity {
public static test instance;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
test.instance = this;
}
public String getHello() {
return "Hello";
}
}
And in Unity, I have placed the .jar file in the Plugins → Android folder. I have a c# class on the main camera, as such:
using UnityEngine;
using System.Collections;
public class CheckSDK : MonoBehaviour {
public AndroidJavaClass _nabiSDK;
private string str = "NOTHING";
void OnGUI() {
if(GUI.Button(new Rect(300, 0, 100, 50), "Get mode...")) {
AndroidJavaClass jc = new AndroidJavaClass("com.example.test.test" );
AndroidJavaObject jo = jc.GetStatic<AndroidJavaObject>("instance");
print(jo.Call<string>("getHello"));
}
}
}
UPDATE: So, I am pressing the button on the device, but I only get an exception that reads: JNI: Init’d AndroidJavaObject with null ptr! Can anyone explain what I’m not doing, and why it is required? I’m going crazy trying to figure it out!
I am deploying to android -- thanks for the update! I'll try it out, and keep you posted. Cheers, Simon
– Catlard