代码之家  ›  专栏  ›  技术社区  ›  MUSTAFA KAYA

如何识别电子邮件的收件人?

  •  0
  • MUSTAFA KAYA  · 技术社区  · 2 年前
      //Intent to gmail        
      Intent sendIntent = new Intent();
                    sendIntent.setAction(Intent.ACTION_SEND);
                    sendIntent.setData(Uri.parse("mailto:"));
                    //how can ı add this part
                    sendIntent.putExtra(Intent.EXTRA_EMAIL,fromEmail);
                    sendIntent.putExtra(Intent.EXTRA_SUBJECT, "Feedback");
                    sendIntent.putExtra(Intent.EXTRA_TEXT, emailBody);
                    sendIntent.setType("text/plain");
                    try {
                        Intent shareIntent = Intent.createChooser(sendIntent, "Feedback");
                        startActivity(shareIntent);
                        Log.i("Finished sending email...", "");
                    } catch (android.content.ActivityNotFoundException ex) {
                        Toast.makeText(MainActivity.this, "There is no email client installed.", Toast.LENGTH_SHORT).show();
                    }
    

    发送器工作正常,但我无法接收。你能帮助我吗?

    1 回复  |  直到 2 年前
        1
  •  0
  •   Nisa Efendioglu    2 年前

    我不知道设计是怎样的。我也不确定你从哪里收到收件人的电子邮件,但也许这段代码对你有用。:)

    public void contact() {
                final Intent send = new Intent(Intent.ACTION_SENDTO);
    
                final String email = "youremail@gmail.com";
                final String subject = "subject";
                final String body = "body...";
    
                final String uriText = "mailto:" + Uri.encode(email) +
                        "?subject=" + Uri.encode(subject) +
                        "&body=" + Uri.encode(body);
                final Uri uri = Uri.parse(uriText);
    
                send.setData(uri);
                startActivity(Intent.createChooser(send, getString(R.string.settings_email_chooser)));
            }