2017-10-17 54 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 
}