我想将数据发送到另一个特定应用。以下内容将String发送到指定的应用程序。
如何向应用发送3个字符串? 我是否必须将它们放入数组或使用HashMap?
Intent sendIntent = new Intent();
sendIntent.setClassName("com.example.application",
"com.example.application.MainActivity");
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, "String1");
sendIntent.setType("text/plain");
startActivity(sendIntent);
提前致谢
答案 0 :(得分:1)
您可以使用更多putExtra&只需使用其他名称!
Intent sendIntent = new Intent();
sendIntent.setClassName("com.example.application",
"com.example.application.MainActivity");
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra("First", "String1");
sendIntent.putExtra("Second", "String2");
sendIntent.putExtra("Third", "String3");
sendIntent.setType("text/plain");
startActivity(sendIntent);
获得字符串:
String first = null;
String second = null;
String third = null;
if (savedInstanceState == null) {
Bundle extras = getIntent().getExtras();
if(extras != null) {
first = extras.getString("First");
second= extras.getString("Second");
third = extras.getString("Third");
}
}
答案 1 :(得分:0)
在发件人应用
中String[] myStrings = new String[] {"string1", "string2","string3"};
intent.putExtra("strings", myStrings);
在接收器应用
中String[] myStrings = intent.getStringArrayExtra("strings");
从here获得。
答案 2 :(得分:0)
Intent sendIntent = new Intent();
sendIntent.setClassName("com.example.application",
"com.example.application.MainActivity");
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra("StringOne", "StringValue1");
sendIntent.putExtra("StringThree", "StringValue3");
sendIntent.putExtra("StringTwo", "StringValue3");
sendIntent.setType("text/plain");
startActivity(sendIntent);
收到的活动
getIntent().getStringExtra(StringOne);
getIntent().getStringExtra(StringThree);
getIntent().getStringExtra(StringTwo);