newOnAndroid
newOnAndroid

Reputation: 141

Android App to App Communication

I am android beginner. Please, give me suggestion that which procedure do I will follow to develop the app like:

For example: How I can communicate between App to App? Like for example I want to sent an image or any other data to the another device or App, Kindly help me out with this.

Thank You

switch (intent.getIntExtra(Constants.EXTENDED_DATA_STATUS,
                Constants.STATE_ACTION_COMPLETE)) {

OR

Is there any possibility app to app communication without using push notification? I want to send an image from one app to another,some suggestion and advice will be much appreciated.Thanks

Upvotes: 1

Views: 757

Answers (2)

David S.
David S.

Reputation: 6705

The communication between apps on a device is very different from communication between devices.

Within a device, you communicate between apps using Intents.

// send text
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, "This is my text to send.");
sendIntent.setType("text/plain");
startActivity(sendIntent);

// send binary data
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_STREAM, uriToImage);
shareIntent.setType("image/jpeg");
startActivity(Intent.createChooser(shareIntent, getResources().getText(R.string.send_to)));

If you want to share between devices on a network, then using some sort of TCP/IP or UDP protocol may work, but generally I find that Bluetooth is the easiest solution. Both applications need to be aware of the communication, but it's straightforward enough.

There is a good article here: http://java.dzone.com/articles/bluetooth-data-transfer

Essentially, the gist's that you:

  1. Find the other device
  2. Pair with the other device
  3. Send the file

The sample code looks like this:

import android.bluetooth.BluetoothAdapter;
// duration that the device is discoverable
private static final int DISCOVER_DURATION = 300;

// our request code (must be greater than zero)
private static final int REQUEST_BLU = 1;
//...
public void enableBlu(){
// enable device discovery - this will automatically enable Bluetooth
Intent discoveryIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);

discoveryIntent.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION,
                            DISCOVER_DURATION );

startActivityForResult(discoveryIntent, REQUEST_BLU);
}

Then to receive:

// When startActivityForResult completes...
protected void onActivityResult (int requestCode,
                                 int resultCode,
                                 Intent data) {

  if (resultCode == DISCOVER_DURATION
       && requestCode == REQUEST_BLU) {
      // processing code goes here
  }
  else{ // cancelled or error
    Toast.makeText(this, R.string.blu_cancelled,
                   Toast.LENGTH_SHORT).show();
  }
}

You can use your own Bluetooth intent instead of the OS one too, if you need to do so. You can get the source for the Bluetooth intent from the AOSP code.

Upvotes: 0

Moubeen Farooq Khan
Moubeen Farooq Khan

Reputation: 2885

To Share The Data Between the Devices One of the way is Wi-Fi Direct For that here is the link for the demo source code and the documentation is on This link. Hope It Will Help.

Upvotes: 1

Related Questions