Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - communicating between two devices

Tags:

What is the best way for an Android app installed on two devices to communicate with each other? Can the devices connect directly without using text messaging?

like image 676
Zishan Neno Avatar asked Mar 07 '12 20:03

Zishan Neno


People also ask

How can I communicate between two services in Android?

You have to use BroadcastReceiver to receive intents, and when you want to communicate simply make an Intent with appropriate values. This way you should be able to make a 2-way communication between any component.

Which is a communication between any two devices?

Data communication happens in the form of signals between two or more computing devices or nodes. The transfer of data happens over a point-to-point or multipoint communication channel.

Can Android apps talk to each other?

Android inter-process communication At the simplest level, there are two different ways for apps to interact on Android: via intents, passing data from one application to another; and through services, where one application provides functionality for others to use.


1 Answers

You have several options, depending on your requirements and setup:

  • If your devices are very close to one another (up to about 10 meters), you can communicate using Bluetooth, as Derek suggested.
  • If your devices are somewhat further away, but within WiFi range of each other (up to about 100 meters), then they can communicate with each other using the Peer-to-Peer WiFi API, documented here (part of the Android Wireless API). This does not require a WiFi router to be present, and the devices will find each other and communicate directly. This does however require Android 4.1 or higher.
  • The Android Wireless API will also work if your devices are on the same local network (i.e., use the same WiFi router), even if they are not themselves within range of each other.
  • If none of these options are viable/guaranteed, then I agree with Derek that the easiest way would be to use ServerSocket and Socket to create a server/client interface through the Internet. Here is a sample application doing that. The main problem you might encounter is that if the server is sitting behind a NAT (such as a home internet router), you will have to configure the NAT to forward the incoming packets to your Android server.
like image 50
Zvika Avatar answered Sep 25 '22 09:09

Zvika