|
Hello, I'm trying to create a java plugin to get compass info from Android. I started with this example: http://docwiki.unity3d.com/uploads/Main/AndroidJavaPluginProject.zip 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, Joel
(comments are locked)
|
|
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. PERFECT! It works! Thank you very much!
Jan 24 '11 at 12:13 PM
jsr2k1
I'm totally new to Java, but not C#. The above almost makes sense to me, but I can't get it to work. All the JNI stuff and JavaVM seems to have been changed (removed) and I had to update the Java code to get it to compile. It ran on my Galaxy tab then crashed, though I didn't mean to run it, but I couldn't find a build command for Java. Where is the C++ code that reads the java? Would this be easier now with AndroidJNI and AndroidJavaObject helpers in Unity? I'm trying to access the gyro on my galaxy tab, but Unity says it's not available (and of course, it actually is available), but I have spent the last 8 hours trying to get something working and I am now at a loss, any help in getting the java code into Unity would be really appreciated (preferably without needing Unity Pro, but I sense that is a necessity).
Aug 17 '11 at 06:55 AM
Talimar
Hey Blitzwing - I'm still trying to get this working. Have a thread in the forum with my code so far. Hoping someone from UT will chime in and answer my questions: http://forum.unity3d.com/threads/100751-Android-Plugin-JNI-Question
Aug 17 '11 at 06:21 PM
Joshua Falkner
(comments are locked)
|
|
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 Forum thread: http://forum.unity3d.com/threads/101279-GyroDroid-2.0-Access-each-and-every-sensor-on-Android-devices-RELASED
(comments are locked)
|
|
philo, try this: I'm having the same issue as Philo. I'm able to compile the .class and .jar file, but when I run it my device it crashes. Did you have to recompile the .cpp and recreate the http://libjavabridge.so?
Jun 05 '11 at 03:57 PM
Joshua Falkner
Actually I just figured out the crashing issue - I wasn't signing the jar. Looking in the build_plugins.sh showed me all the steps I was missing.
Jun 05 '11 at 04:29 PM
Joshua Falkner
(comments are locked)
|
|
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. philo
(comments are locked)
|
