2017-10-17 58 views
-1

我目前正在用简单的表单编写一个应用程序,当您单击提交时,打开一封电子邮件并将输入到textviews中的数据自动填充到邮件正文中。从android中的textview调用数据java

protected void sendEmail() { 

      EditText nameField = (EditText) findViewById(R.id.nameField); 
      String nameValue = nameField.getText().toString(); 

      EditText dateField = (EditText) findViewById(R.id.dateField); 
      String dateValue = dateField.getText().toString(); 

      EditText ahsField = (EditText) findViewById(R.id.ahsField); 
      String ahsValue = ahsField.getText().toString(); 


      Log.i("Send email", ""); 
      String[] TO = {""}; 
      Intent emailIntent = new Intent(Intent.ACTION_SEND); 

      emailIntent.setData(Uri.parse("mailto:")); 
      emailIntent.setType("text/plain"); 
      emailIntent.putExtra(Intent.EXTRA_EMAIL, TO); 
      emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Your subject..."); 
      emailIntent.putExtra(Intent.EXTRA_TEXT, "MESSAGE BODY HERE?"); 

      try { 

       startActivity(Intent.createChooser(emailIntent, "Send mail...")); 
       finish(); 
       Log.i("Finished sending email", ""); 
      } catch (android.content.ActivityNotFoundException ex) { 
       Toast.makeText(DDActivity.this, "There is no email client installed", Toast.LENGTH_SHORT).show(); 
      } 

     } 

这是我到目前为止,任何帮助将不胜感激!

+0

那你想干什么?你的问题是什么? –

+0

您的意思是说,您想填写主题以及textviews中的文字吗?请设置文字视图名称,以便理解。 – motis10

回答

0

下面的代码工作刚刚试了一下

Intent i = new Intent(Intent.ACTION_SEND); 
i.setType("message/rfc822"); 
i.putExtra(Intent.EXTRA_EMAIL, new String[]{"[email protected]"}); 
i.putExtra(Intent.EXTRA_SUBJECT, "subject of email"); 
i.putExtra(Intent.EXTRA_TEXT , "body of email"); 
try { 
    startActivity(Intent.createChooser(i, "Choose email..."); 
} catch (android.content.ActivityNotFoundException ex) { 
    // handle edge case where no email client is installed 
}