Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

bluetooth in libgdx project on Android

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.

like image 312
AlgoRhymes Avatar asked Nov 24 '25 12:11

AlgoRhymes


2 Answers

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).

like image 78
aacotroneo Avatar answered Nov 27 '25 01:11

aacotroneo


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.

like image 24
Umz Games Avatar answered Nov 27 '25 02:11

Umz Games



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!