8

I need to send some string data from my one application activity to my other application activity in android and not between the activities within the same application. How to do that? What intent filters my other application need to declare? Please try to elaborate with example.....

SACHIN DHIVARE
  • 115
  • 1
  • 1
  • 7

3 Answers3

17

As far as I could understand from your answer you're looking for intents:

On the manifest of App A - Activity Alpha you declare a intent filter with Category DEFAULT and Action = com.your_app_package_name.your_app_name.ActivtiyAlpha

The on App B, Activity Beta you put the code to launch A and pass the data:

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

Then back on App A - Activity Alpha you put the code:

Bundle b = getIntent().getExtras();
if(b!=null){
    String myString = b.getString("KEY_DATA_EXTRA_FROM_ACTV_B");
    // and any other data that the other app sent
}
Alfergon
  • 5,463
  • 6
  • 36
  • 56
Budius
  • 39,391
  • 16
  • 102
  • 144
  • Thanx for your reply....I have done that as you say but the app that is sending intent got stopped...when I saw the log then it shows permission denial: Starting intent action = ........ – SACHIN DHIVARE Jan 16 '13 at 11:36
  • 1
    In the manifest, mark the activity that will receive the intent as Enabled and Exported. – Budius Jan 16 '13 at 12:20
2

If you're concerned with only a small amount of data, Android provides a SharedPreferences class to share preferences between applications. Most notably, you can add OnSharedPreferenceChangeListener to each application so they can be notified when the other changes the value.

Most importantly, you can't ensure that both applications are running

You can find more information on http://developer.android.com/guide/topics/data/data-storage.html

user1954492
  • 495
  • 3
  • 13
0

I comunicate two apps by using brodcast passing gps coordenates from app A to app B

This is in APP B (who sends the data)

Intent sendGPSPams = new Intent();
sendGPSPams.setAction(ACTION_GET_GPS_PARAMS);
sendGPSPams.putExtra("Latitude",latitude);
sendGPSPams.putExtra("Longitude",longitude);
sendGPSPams.putExtra("Velocity",velocity);
sendGPSPams.putExtra("DOP",PDOP);
sendGPSPams.putExtra("Date",time);
sendGPSPams.putExtra("Bearing", bearing);

sendBroadcast(sendGPSPams);

This is in app A who receives the gps params or the data sent from app B

private  BroadcastReceiver   myBrodcast = new BroadcastReceiver() {
double latitude;
double longitude;
double velocity;
double DOP;
String date;

double bearing;
@Override
public void onReceive(Context context, Intent intent) {


        if (intent.getAction().equals(ACTION_GET_GPS_PARAMS)) {

            latitude = intent.getDoubleExtra("Latitude", 0);
            longitude = intent.getDoubleExtra("Longitude", 0);
            velocity = intent.getDoubleExtra("Velocity", 0);
            DOP = intent.getDoubleExtra("DOP", 0);
            date = intent.getStringExtra("Date");
            bearing = intent.getDoubleExtra("Bearing", 0);
            String text = "Latitude:\t" + latitude +"\nLongitude\t"+ longitude +
                    "\nVelocity\t" +velocity +"\nDOP\t" + DOP +"\n Date \t" + date +"\nBearing\t" + bearing;
            tv_text.setText(text);

    }
}

};

Pleas look at this videos.

Brodcast