Can anyone give me a piece of advice about using bluetooth in libgdx games on Android?
My problem is that the whole code is in MyGame project and in MyGame-Android there is only MainActivity class that starts the game on Android.
I can get bluetooth to work in normal Android application but MyGame libgdx project can't see classes that are in MyGame-Android project.
If you want to use non-multiplatform code in libgdx, you should create an interface on the agnostic project (MyGame), and implement it on the native project (MyGame-Android). Then, on the native project create the implementor object and pass it to the MyGame instance. The interface will hold all the methods that you said are not accessible (a tip: try to can encapsulate the most you can regarding the bluetooth management and expose only methods relevant to your game, so you don't have to create a huge interface).
In case anyone else finds there way here on their journey to create Bluetooth-able apps. I think the best starting place is the Android Developer guide to get a firm grasp and understanding of Bluetooth on its own - Create a working application with what they have there http://developer.android.com/guide/topics/connectivity/bluetooth.html
After that, using the method above, you can implement the code. A working example is http://algorhymes.wordpress.com/2013/02/07/java-bluetooth-on-android-with-and-wo-libgdx/ but I recommend understanding the Bluetooth first, it makes debugging much much easier.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With