在androidstudio中添加mailto intent后,java主题和主体不会出现

yfwxisqw  于 2021-06-29  发布在  Java
关注(0)|答案(1)|浏览(295)

我已经做了一个基本的应用程序(使用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);
    }
}
tyg4sfes

tyg4sfes1#

这个简单的实现对我很有用:

Intent i = new Intent(Intent.ACTION_SENDTO);
    i.setData(Uri.parse("mailto:badreddine@bou-devlpr.xyz"));
    i.putExtra(Intent.EXTRA_SUBJECT, "Feedback/Report");
    startActivity(i);

相关问题