I referred to here until I called the jar in the first place https://ghoul-life.hatenablog.com/entry/2019/01/26/030622
When I tried to call the sensor related function of the terminal in the called java method, NoClassDefFoundError has occurred Apparently I lose track of the class itself when trying to use android context inside a method.
I found a way to send android context from Unity to java and the call was successful. https://www.itread01.com/content/1546405986.html
Unity:
AndroidJavaClass androidJavaClass = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
AndroidJavaObject activity = androidJavaClass.GetStatic<AndroidJavaObject>("currentActivity");
AndroidJavaObject javaPlayer = new AndroidJavaObject("jp.co.sample.MyClass");
string isSensorAvalable = javaPlayer.Call<string>("myMethod", activity);
// With or without step sensor "true" / "false"
Java:
public String myMethod(Activity mainActivity) {
Context context = (Context) mainActivity;
PackageManager packageManager = context.getPackageManager();
return String.valueOf(packageManager.hasSystemFeature(PackageManager.FEATURE_SENSOR_STEP_COUNTER));
//歩数センサーが端末にあるかどうかを返す }
Recommended Posts