【发布时间】:2021-04-03 03:52:03
【问题描述】:
我制作了一个基本应用程序(使用 Java),它通过电子邮件将订单摘要发送给用户。在运行该应用程序时,它会在下订单时打开 Gmail,但电子邮件的主题和正文字段仍然为空,即使我已在意图中指定它们。任何地方都没有错误。我该如何解决?
// This method is called when the order button is clicked.
public void submitOrder(View view) {
CheckBox checkWhippedCream = findViewById(R.id.whippedcream);
boolean hasWhippedCream = checkWhippedCream.isChecked();
CheckBox checkChocolate = findViewById(R.id.chocolate);
boolean hasChocolate = checkChocolate.isChecked();
EditText nameField = findViewById(R.id.naam);
String name = name.getText().toString();
int price = calculatePrice(hasWhippedCream, hasChocolate);
// The order summary will be formed.
String priceMessage = createOrderSummary(price, hasWhippedCream, hasChocolate, name);
displayMessage(priceMessage); // displayMessage will display the order summary in the app.
Intent intent = new Intent(Intent.ACTION_SENDTO);
intent.setData(Uri.parse("mailto: "));
intent.putExtra(Intent.EXTRA_SUBJECT, "CoffeeShoppee Order for " + name);
intent.putExtra(Intent.EXTRA_TEXT, priceMessage);
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(intent);
}
}
【问题讨论】:
标签: java android android-intent mailto