I want to make a virtual joystick in my Android application for controlling an RC car. How can I accomplish this? Is there an API that I can use to do this? The code samples that I have checked out online do not seem to work.
Virtual Joystick in Android SDK
You can have a look at this one, very simple (with documentation, etc.) https://github.com/controlwear/virtual-joystick-android
Just add to your build.gradle
file compile 'io.github.controlwear:virtualjoystick:0.9.9'
and then:
JoystickView joystick = (JoystickView) findViewById(R.id.joystickView);
joystick.setOnMoveListener(new JoystickView.OnMoveListener() {
@Override
public void onMove(int angle, int strength) {
// do whatever you want
}
});
EDIT:
As of new updates, compile
is obsolete, instead you should use implementation
or api
, as follows:
implementation 'io.github.controlwear:virtualjoystick:1.10.1'
(1.10.1 updated version)
The minSDK
as the author says is 16 (Android Jelly Bean).
© 2022 - 2024 — McMap. All rights reserved.