2012-11-29 13 views
0

양식 기반 응용 프로그램을 개발 중입니다. 이 양식에는 고객 세부 사항이 포함됩니다. 그가 제출 버튼을 클릭하면 양식의 세부 사항이 이메일 본문으로 포함됩니다.본문에 양식 세부 정보가 포함 된 이메일을 보내는 방법은 무엇입니까?

Orders.java

import android.app.Activity;  
import android.content.Intent; 
import android.os.Bundle; 
import android.view.View; 
import android.view.View.OnClickListener; 
import android.widget.Button; 
import android.widget.EditText; 
import android.widget.Toast; 

public class Order extends Activity{ 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.order); 
     final EditText name = (EditText)findViewById(R.id.username); 
     final EditText mail = (EditText)findViewById(R.id.email); 
     final EditText phone = (EditText)findViewById(R.id.phone); 
     final EditText product = (EditText)findViewById(R.id.product); 
     final String _name = name.getText().toString(); 
     final String _mail = mail.getText().toString(); 
     final String _phone = phone.getText().toString(); 
     final String _product = product.getText().toString(); 
     System.out.println(_name); 
     System.out.println(_mail); 
     System.out.println(_phone); 
     System.out.println(_product); 
     Button email = (Button) findViewById(R.id.Button01); 
     email.setOnClickListener(new OnClickListener(){ 
        public void onClick(View v){ 
        String[] recipients = new String[]{"[email protected]", "",}; 
         StringBuilder body = new StringBuilder(); 
         StringBuilder body1 = new StringBuilder(); 
         body1.append("To: " + recipients); 
         body.append("Name: "+name.getText().toString()); 
         body.append("\n\n\nMail: "+mail.getText().toString()); 
         body.append("\n\n\nPhone: "+phone.getText().toString()); 
         body.append("\n\n\nProduct: "+product.getText().toString()); 
         Intent i = new Intent(android.content.Intent.ACTION_SEND); 
         i.setType("text/plain"); 
         i.putExtra(android.content.Intent.EXTRA_EMAIL, body1.toString()); 
         i.putExtra(android.content.Intent.EXTRA_SUBJECT, "Customer Details"); 
         i.putExtra(android.content.Intent.EXTRA_TEXT, body.toString()); 
startActivity(i); 
} 
}); 
} 
} 

XML 파일은 다음과 같습니다 : 아래

내 코드 나에 프로그램에 주어진다 메일 ID를 얻고있다

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" >  

    <EditText 
     android:layout_width="60dip" 
     android:layout_height="wrap_content" 
     android:id="@+id/edit"/> 

    <Button 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:id="@+id/btn" 
     android:text="Click"/>  
</LinearLayout> 

"에서를" 입력란에 입력란을 입력하고 싶습니다.

+0

귀하의 질문은 무엇입니까? – Elemental

+0

deatails는 관리자에게 메일로 보내야합니다 ... – Abhay

+0

무엇이 문제입니까? 전자 메일을 보내거나 본문에 세부 정보를 가져 오는 중입니까? – ThePCWizard

답변

1
StringBuilder body = new StringBuilder(); 
     body.append("Name: "+nameField.getText().toString()); 
     body.append("\nAge: "+ageField.getText().toString()); 
     body.append("\nGender: "+genderField.getText().toString()); 

     // Sending to admin 
     Intent i = new Intent(Intent.ACTION_SEND); 
     i.setType("text/plain"); 
     i.putExtra(Intent.EXTRA_EMAIL, new String[] {"[email protected]"}); 
     i.putExtra(Intent.EXTRA_SUBJECT, "Customer Details"); 
     i.putExtra(Intent.EXTRA_TEXT, body.toString()); 
     startActivity(i); 

희망이 있습니다.

1

StringBuilder을 사용해야합니다. 당신의 끈. 메일은 html 형식이어야합니다. 따라서 Html.fromHtml(sb.toString());과 같은 html 지원 클래스의 메소드를 사용해야합니다.

문자열에 추가하고 메일 본문 영역으로 보낼 일부 텍스트 만 표시하면 양식을 보낼 수 있습니다.

public StringBuilder sb; 
sb= new StringBuilder(); 

    // This is Mail Format That will be show in Body area and send to be customer. 

    sb.append("<p><b><font color=\"#8CC248\">Title</b></p>"); 
    sb.append("<p><b><font color=\"#000000\">Dear,"+ edittextvalue in string mode +",</b></p>"); 

지금

Intent i2 = new Intent(android.content.Intent.ACTION_SEND);  
i2.setType("text/html"); 
i2.putExtra(android.content.Intent.EXTRA_TEXT,Html.fromHtml(sb.toString())); 

당신의 출력을 참조하십시오이 onClick 이벤트에게 메일을 보낼 수 있습니다.