connecting 2 android devices without Internet
Hi, the only answers I saw on this forum about connecting via bluetooth where about connecting an Arduino with an android via SerialPort and buying the "Android Bluetooth Plugin" from the store. Since I will not buy that and I didn't understand anything about SerialPort, can someone explain how to make these things right below?
(I'm planning to do an offline-multiplayer game)
choose what device you want to connect with
sending a simple float through that connection
making the other device read that float so I can do whatever I want with it
Answer by WazzaM · Oct 04, 2017 at 09:07 PM
Hi @LetsStartSomeSeriousCoding
Without internet, you can make two androids communicate via:
1) wifi - one doing hotspot 2) NFC -- https://developer.android.com/guide/topics/connectivity/nfc/nfc.html
3) bluetooth classic with RFCOMM profile sending bytes 4) bluetooth low energy (LE)
wifi (1) is not so practical because the users need to really cooperate and share a hotspot password. That said, BT requires devices to pair so there's trust required either way...
None of them will be trivial. Bluetooth is becoming a security problem and not so easy from Unity. NFC would be available on most phones from the last couple of years or so - maybe 2013 onwards.
Personally, I think Wifi or NFC is worth a go but regardless you will spend a chunk of time getting this working. You'll need to think about one device playing a server role and the other playing as client. Client would initiate connection (true for BT and Wifi) and server would listen, waiting for new connections. I haven't haven't tried NFC yet but it's the newer thing...
Also, I'd like to see the Android API made easier from Unity so I've started a little API for Unity C# code to expose the Android API. I'm thinking of putting it on the Asset Store and curious if you'd think that might be of interest to you.
All the best,
WazzaM