【问题标题】:Subject and body don't show up after adding mailto intent in Android Studio在 Android Studio 中添加 mailto 意图后,主题和正文不显示
【发布时间】: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


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 2020-04-06
      • 2019-01-08
      • 1970-01-01
      • 1970-01-01
      • 2021-12-23
      • 1970-01-01
      • 2018-04-21
      • 1970-01-01
      相关资源
      最近更新 更多