2

This is my app A and have a string value "Hello" . I want to send this string value to app B.

String mystring = "Hello";
Intent launchIntent = getPackageManager().getLaunchIntentForPackage("com.example.test");
if (launchIntent != null) {
    launchIntent.putExtra("success", mystring);
    startActivity(launchIntent);
}

This is my app B

Bundle b = getIntent().getExtras();
if (b != null) {
    String myString = b.getString("success");
    Toast.makeText(MainActivity.this, "" + myString, Toast.LENGTH_SHORT).show();
}

On the receiving "app B" myString is received as null.

marcelovca90
  • 2,673
  • 3
  • 27
  • 34
Guruprasas
  • 125
  • 1
  • 7
  • 3
    Possible duplicate of [How to send data from one application to other application in android?](http://stackoverflow.com/questions/14355860/how-to-send-data-from-one-application-to-other-application-in-android) – samiles Dec 16 '16 at 13:17
  • Directly you can't data from app one to another. If you want to send some data from one app to another then you can use content provider. https://developer.android.com/guide/topics/providers/content-providers.html – ViramP Dec 16 '16 at 13:24
  • Also relevant. http://stackoverflow.com/questions/5745243/data-sharing-between-two-applications – OneCricketeer Dec 16 '16 at 15:47

1 Answers1

4

On the manifest of app B,

You need to declare a intent filter with Category DEFAULT and Action=com.your_app_package_name.your_app_name.ActivtiyAlpha

Then you need to set that action in your Intent to start that activity for app A and send extra data in intent.

Intent i = new Intent("com.your_app_package_name.your_app_name.ActivtiyAlpha");
i.putExtra("KEY_DATA_EXTRA_FROM_ACTV_B", myString);
// add extras to any other data you want to send to b
launchIntent.putExtra("success",mystring);
startActivity(launchIntent);

Checkout detailed Answer here

Community
  • 1
  • 1
Priyank Patel
  • 12,244
  • 8
  • 65
  • 85