2017-10-17 5 views
-1

私は現在、送信をクリックすると電子メールが開き、textviewsに入力されたデータが自動的にメッセージ本文に入力されるという単純なフォームのアプリケーションを作成しています。android stuido javaのtextviewからデータを呼び出す

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の件名とテキストを入力することを意味しましたか?理解できるように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 
} 
関連する問題