2011-08-07 8 views
1

は、私の質問は...のonclickの方法を常にハードコードされているアドレスにメールを送信するメールボタンを送信する方法であるAndroidの送信メールは私がのEditTextを持って、次のmain.xmlで

mail.setOnClickListener(

     @Override 
     public void onClick(View v) { 
     //How to sendmail to adress [email protected] oblibk of send mail button 

    }); 

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:id="@+id/linearLayout3" android:layout_width="fill_parent" android:layout_height="fill_parent"> 
     <EditText android:id="@+id/editText2" android:layout_width="fill_parent" android:layout_height="wrap_content"> 
     <requestFocus></requestFocus> 
     </EditText> 
     <Button android:text="Send Mail" android:id="@+id/mail" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button> 
     <Button android:text="Back" android:id="@+id/back2" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button> 


    </LinearLayout> 

答えて

5
final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);  
emailIntent.setType("plain/text");  
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{"[email protected]"});  
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, yourSubject);  
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, yourBodyText);  
context.startActivity(Intent.createChooser(intent, "Send mail...")); 
+3

代わりに 'Intent.setType(" message/rfc822 ")'を使用する – mibollma

+0

これは新しい活動を開始するだろう..?私はこの方法を望んでいない...ボタンをクリックするとメッセージが郵送されるべきだ – Rajeev

+0

それは開くだろうユーザーのメールアプリケーション彼らはそこからメールを送ることができ、あなたの活動に戻されます。これは正しいことです。あなたは車輪を再構築しようとしているようです。ユーザが入力するための 'EditText'を持つ必要はありません。これは、ユーザの電子メールアプリケーションで行う必要があります。 – dfetter88

関連する問題