0

I wish to use this native plugin for Android devices via Unity. For some reason the plugin is just now working. When I run it on a real device the game crashes. I am using Unity 5.5.2f1 personal, my phone is Samsung Edge 6 with Marshmallow api.

I have placed the jar file inside Assest/Plugins/Android. I can't figure out what is the cause for this error. Do you know what is wrong here?

This is part of my code:

 private AndroidJavaObject plugin;

void Start ()
{
    plugin = new AndroidJavaClass("jp.kshoji.unity.sensor.UnitySensorPlugin").CallStatic<AndroidJavaObject>("getInstance");

    //Init the ambienttemperature sensor
    if (plugin != null) 
    {
        plugin.Call("startSensorListening", "ambienttemperature");
    }

}
Programmer
  • 121,791
  • 22
  • 236
  • 328
Tal Angel
  • 1,301
  • 3
  • 29
  • 63
  • Just try use patches version of Unity, example Unity 5.5.1p4 – OnionFan Mar 12 '17 at 13:28
  • I am able to run other AndroidJavaClass in my code. I want to be able to solve my problem on Unity 5.5.2. – Tal Angel Mar 12 '17 at 17:59
  • Sorry for the long reply. I finally took some time off to look at this today and I found that that the crash happens when the sensor is not supported on the device and the array returned is `null`. So, you have to check if the sensor exist before getting the values. – Programmer Mar 19 '17 at 00:22

0 Answers0