我已经做了一个基本的应用程序(使用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);
}
}
1条答案
按热度按时间tyg4sfes1#
这个简单的实现对我很有用: