I'm trying to create a java plugin to get compass info from Android. I started with this example:
Then, I tried to include the necessary code from:
The problem I found is that it is necessary to create a SensorListener and I'm not sure if this will work as a Unity plugin.
Anyone has tried to do this?
This is my piece of code:
The alternative is to code the plugin with native code (NDK), but sensor data is only available with Android SDK 2.3 (Almost every android phone runs 2.2 nowadays)
Thanks in advance,
asked Jan 20 '11 at 03:23 PM
I think you should be able to do it. However you will have to pull the data from the sensor each cycle, instead of having the data pushed to you from the java EventBus.
The following is just pseudo-code so don't hold me to it but it should be something like:
This way you have a standalone java class that is aggregating the sensor updates for you then you just need to instantiate and call the getters from your .cs code
Then on each update cycle you can call the
methods to get the current X,Y,Z values respectively. Again this is just pseudocode so it probably won't compile :) But you get the idea.
answered Jan 20 '11 at 09:06 PM
There is a plugin by Prefrontal Cortex in the asset store, which provides access to each and every android sensor. If you don't want to write your own, you could give it a try.
Demo scene (type into your mobiles' browser to install): goo.gl/oLkOQ
answered Sep 06 '11 at 04:18 PM
philo, try this:
answered Apr 12 '11 at 10:22 AM
I understand (in theory) how this code works, but i can't get the SensorManager to work.
I managed to build the JavaPluginSample project in Eclipse but the game crashes instantly when i include this part of the code:
Maybe you can push me in the right direction.
answered Apr 11 '11 at 07:05 AM