No joysticks retrieved

Hello,

I’m using Android 3.2 and I’m trying to retrieve position and orientation information from the sensors on my android device, but when I do this:

[java]Joystick[] joysticks = inputManager.getJoysticks();[/java]

joysticks array doesn’t contain any elements.

My constructor looks like this:

[java]public static void main(String[] args)
{
Main app = new Main();
AppSettings settings = new AppSettings(true);
settings.setUseJoysticks(true);
app.setSettings(settings);
app.start();
}[/java]

And I’ve also added these lines to the AndroidManifest.xml file:

<uses-feature android:name=“android.hardware.location” />
<uses-feature android:name=“android.hardware.sensor.accelerometer” />
<uses-feature android:name=“android.hardware.sensor.compass” />
<uses-feature android:name=“android.hardware.sensor.gyroscope” />

Am I missing something? Should I do anything else to make it work?

Thank you very much!

Sorry, to be more precise, it’s not like the joysticks array is empty, actually inputManager.getJoysticks() call is returning null.

I’ve also tried with another device: a samsung galaxy note 10.1 with android 4.1.2, but same problem… I’ve tried to run several code samples I’ve found in the forum but nothing. I know I must be doing something wrong but I’m new at this and I don’t know what else to try… Thank you again! :slight_smile:

I’ve never used Android before but I found this after poking around for 20 seconds:
http://hub.jmonkeyengine.org/javadoc/com/jme3/app/AndroidHarness.html#joystickEventsEnabled

Indeed, adding this line:

[java]this.joystickEventsEnabled = true;[/java]

in the constructor of the MainActivity class solved the problem. I just thought that including this line:

[java]settings.setUseJoysticks(true);[/java]

in the main method was enough. In other words, I thought that using the joystick abstraction there was no need of editing the MainActivity class.

Thank you for your help.

@fegarcia said: Indeed, adding this line:

[java]this.joystickEventsEnabled = true;[/java]

in the constructor of the MainActivity class solved the problem. I just thought that including this line:

[java]settings.setUseJoysticks(true);[/java]

in the main method was enough. In other words, I thought that using the joystick abstraction there was no need of editing the MainActivity class.

Thank you for your help.

Most of what’s on settings is for desktop.

@fegarcia said: Indeed, adding this line:

[java]this.joystickEventsEnabled = true;[/java]

in the constructor of the MainActivity class solved the problem. I just thought that including this line:

[java]settings.setUseJoysticks(true);[/java]

in the main method was enough. In other words, I thought that using the joystick abstraction there was no need of editing the MainActivity class.

Thank you for your help.

[java]settings.setUseJoysticks(joystickEventsEnabled);[/java] is set in AndroidHarness. I did it this way so that the MainActivity class could control whether or not the Android sensors were enabled for battery life reasons.

There is a disconnect right now between AndroidHarness (aka MainActivity) and appSettings that I want to eventually clean up.

Also, some work needs to be done in the sensor joystick area to allow for the sensor joystick feedback to be enabled/disabled after the app starts. Right now, it needs to be enabled before the app starts which is why it is located in MainActivity.

Thank you very much, guys. Now I understand.

I’m just starting to develop android games using this SDK and it’s awesome. Congratulations for your work :slight_smile: