Search code examples
javaandroidwifi

Make an Android App receive data from a non-Android App using Wifi


I am working on an app that will act as a dashboard for an electronic card installed in cars and trucks.

I need the application to be able to receive data from this card, so I can display it in various ways on the app. We chose Wifi for the communication method. To access the card, my app is able to connect to a Wifi network created by it.

I would like to receive JSON sent by the card every second. I need help on where to start to make the two devices communicate, and what are the good practices on implementing this kind of communication. The app basically act as a client, and the card as a server. I found something about sockets, but it seemed to use two Android devices, a server and a client, so I'm kinda stuck here.

I use Android Studio 2.1.2 with the Android APIs ranging from 19 to latest.


Solution

  • One option is to broadcast with UDP the data within the local network. The moment the android device connects to the wifi network it will be in its local network. So the data can be received at the android end with a multicast receiver(check out http://jgroups.org/ ).

    Refer example

    It may also use the p2p sharing with TCP and bind the device with static IPs for communication. Create a simple socket receiver at the android end and a service at the device end. Depends on the way you choose it.