Reputation: 124
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
.
Upvotes: 3
Views: 3041
Reputation: 51
Very old question, but I needed kind of the same, so I'm sharing.
I create and app on libgdx and add an implementation to manage bluetooth low energy connections in android and ios. (both are working with a cadence sensor)
All the code is on github if you want
https://github.com/carlgira/ble-cadence-app
I was not sure how the IOS part would work, but basically I translated a Swift bluetooth APP to the robovm java api. There are some differences in names and stuff, but is was almost the same.
Upvotes: 1
Reputation: 71
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.
Upvotes: 1
Reputation: 2220
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).
Upvotes: 2