我正在制作一个表单应用程序,用于收集信息并通过电子邮件发送。 MainActivity收集电话#,然后收集警告消息活动,然后收集名称活动等。我遇到的问题是将从EditText字段收集的数据发送到最终的AgreementActivity作为电子邮件发送,对我来说不起作用。我已经到处寻找,但我无法弄清楚如何在将输入数据发送到最终协议活动时将用户发送到下一个活动,以便可以通过电子邮件发送。
这是我到目前为止所拥有的。
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Find the next button
final Button next1 = (Button) findViewById(R.id.button);
// Find the Edit Text Field to input Phone Number
final EditText phoneField = (EditText) findViewById(R.id.edit_text_phone);
// Set a click listener on the next button
next1.setOnClickListener(new View.OnClickListener() {
// The code in this method will be executed when the next1 Button is clicked on.
@Override
public void onClick(View view) {
// sends data collected from edit text box to be sent to final page so it can be
// sent in an email message.
Intent phoneNumber = new Intent(MainActivity.this, AgreementActivity.class);
phoneNumber.putExtra("phoneMessage", phoneField.getText().toString());
startActivity(phoneNumber);
//starts next activity
Intent nextButton = new Intent(MainActivity.this, Warning.class);
startActivity(nextButton);
}
});
}
}
这是最终的协议活动,它将发送电子邮件。 但电子邮件主题行的最终结果是“您的电话号码为空”
public class AgreementActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.agreement_activity);
// Find the submit button
final Button submit = (Button) findViewById(R.id.button6);
// This is the input from user for phone number field
final Bundle phoneNumber = getIntent().getExtras();
// Set a click listener on that View
submit.setOnClickListener(new View.OnClickListener() {
// The code in this method will be executed when the Submit Button is clicked on.
@Override
public void onClick(View view) {
Intent intent = new Intent(Intent.ACTION_SENDTO);
intent.setData(Uri.parse("mailto:"));
intent.getBundleExtra("phoneMessage");
intent.putExtra(Intent.EXTRA_SUBJECT, "Your Phone Number is " + phoneNumber);
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(intent);
}
}
});
}
}
答案 0 :(得分:1)
在您的AgreementActivity中,使用以下方式获取电话号码:
final String phoneNumber = getIntent().getStringExtra("phoneMessage");
答案 1 :(得分:0)
我会扩展应用class like this,但你可以找到其他方法。如果有人导航箭头
,您需要考虑the backstack