gpt4 book ai didi

java - 将多个 Intent 用于不同的 Activity 和最终的电子邮件 Intent

转载 作者:行者123 更新时间:2023-11-30 00:11:49 24 4
gpt4 key购买 nike

我正在制作一个表单应用程序,用于收集信息并通过电子邮件发送。 MainActivity 收集电话号码,然后是警告消息 Activity ,然后是名称 Activity 等。我遇到的问题是将从 EditText 字段收集的数据发送到最终 AgreementActivity 以作为电子邮件发送,这对我来说不起作用。我到处都看过,但我无法弄清楚如何在将输入数据发送到最终协议(protocol) Activity 时将用户发送到下一个 Activity ,以便可以通过电子邮件发送。

这就是我目前所拥有的。

 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);
}
});

}

这是发送电子邮件的最终协议(protocol) Activity 。但是邮件主题行的最终结果是“您的电话号码为空”

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);
}


}


});
}

最佳答案

在您的 AgreementActivity 中,使用以下方法获取电话号码:

final String phoneNumber = getIntent().getStringExtra("phoneMessage");

关于java - 将多个 Intent 用于不同的 Activity 和最终的电子邮件 Intent ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48029680/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com