Note that there are some explanatory texts on larger screens.

plurals
  1. POSending data among multiple Android devices
    text
    copied!<p>I need a way to send data among multiple Android devices within around ~50 ft bidirectionally. Basically the idea is that one device sends all the other devices within the area a small amount of data and all the other devices send back a small amount of data.</p> <p>After a couple hours of research, I came across multiple ways to implement this: Wi-fi p2p, external server, etc.</p> <p>As far as I know, Wi-fi P2P only let's you connect to one device at a time, which is not what I am trying to accomplish, since I need the device to communicate to multiple devices simultaneously. Also, this way limits my application to enforce the devices to be within the same wireless network.</p> <p>Using an external server would allow as many devices to communicate with one another, but I have no idea how one device would detect devices within a vicinity using this method. I was thinking maybe the devices could communicate their coordinates to the server and have the server analyze the proximity of the devices connected, but I wasn't entirely sure.</p> <p>I am pretty new to Android programming as well as network programming, so any help to guide me in the right direction would be appreciated.</p> <p>Thank you.</p> <hr> <p>Edit:</p> <p>Here's what I have so far. It has no networking elements to it yet. It simply accesses the stock music app and retrieves the current track information. I want to be able to send this information to all nearby devices.</p> <pre><code>public class MainActivity extends Activity { public static final String SERVICECMD = "com.android.music.musicservicecommand"; public static final String CMDNAME = "command"; public static final String CMDTOGGLEPAUSE = "togglepause"; public static final String CMDSTOP = "stop"; public static final String CMDPAUSE = "pause"; public static final String CMDPREVIOUS = "previous"; public static final String CMDNEXT = "next"; public String song_artist = ""; public String song_track = ""; public String song_album = ""; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); IntentFilter iF = new IntentFilter(); iF.addAction("com.android.music.metachanged"); iF.addAction("com.android.music.playstatechanged"); iF.addAction("com.android.music.playbackcomplete"); iF.addAction("com.android.music.queuechanged"); registerReceiver(mReceiver, iF); } private BroadcastReceiver mReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { String action = intent.getAction(); String cmd = intent.getStringExtra("command"); Log.d("mIntentReceiver.onReceive ", action + " / " + cmd); String artist = intent.getStringExtra("artist"); String album = intent.getStringExtra("album"); String track = intent.getStringExtra("track"); TextView music_info = (TextView) findViewById(R.id.musicview); music_info.setText("Track: "+track+ "\nArtist: "+artist+ "\nAlbum: "+album); } }; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload