How to send data from one application to other app

2019-01-18 07:08发布

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.....

4条回答
Ridiculous、
2楼-- · 2019-01-18 07:36

Here is the tutorial for sending and receiving content between applications. check it once

查看更多
叛逆
3楼-- · 2019-01-18 07:38

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
}
查看更多
虎瘦雄心在
4楼-- · 2019-01-18 07:39

Use Shared Preferences. Set Mode to MODE_WORLD_READABLE

SharedPreferences sharedPref = activity.getPreferences(Activity.MODE_WORLD_READABLE);
查看更多
混吃等死
5楼-- · 2019-01-18 07:40

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

查看更多
登录 后发表回答