2011-06-06 7 views
5

का उपयोग कर उन्हें सीधे एक ईमेल पते पर भेजें, मैं वर्तमान में एक एंड्रॉइड एप्लिकेशन पर काम कर रहा हूं जिसमें ऑर्डर फॉर्म है। मैं जानना चाहता हूं कि उपयोगकर्ता को ईमेल ऐप पेज पर लाने के बिना, उपयोगकर्ता को इनपुट करने के लिए एप्लिकेशन को सीधे कैप्चर करने और बटन का उपयोग करके ईमेल पर इनपुट भेजने की अनुमति कैसे दे सकती है। मुझे पता है कि मेरी .java क्लास में त्रुटियां हैं, हालांकि, मैं कोशिश कर रहा हूं ... नीचे मेरी एक्सएमएल (लेआउट) फ़ाइल और मेरी .java क्लास फ़ाइल है। कृपया मेरी मदद करें ... धन्यवाद !!उपयोगकर्ता इनपुट कैप्चर करें और बटन

यहाँ मेरी .xml फ़ाइल (लेआउट) है

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:stretchColumns="1"> 
<TextView 
    android:id="@+id/txtname" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Name: " 
    /> 
<EditText 
    android:id="@+id/editname" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_below="@id/txtname" 
    android:hint="Your name please" 
    /> 
<TextView 
    android:id="@+id/txtemail" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_below="@id/editname" 
    android:text="Email Address: " 
    /> 
<EditText 
    android:id="@+id/editemail" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_below="@id/txtemail" 
    android:hint="Enter email address here" 
    /> 
<TextView 
    android:id="@+id/txtnum" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_below="@id/editemail" 
    android:text="Contact Number: " 
    /> 
<EditText 
    android:id="@+id/editnum" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_below="@id/txtnum" 
    android:hint="Enter contact number here" 
    /> 
<TextView 
    android:id="@+id/txtadd" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_below="@id/editnum" 
    android:text="Mailing Address: " 
    /> 
<EditText 
    android:id="@+id/editadd" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_below="@id/txtadd" 
    android:hint="Enter mailing address here" 
    /> 
<TextView 
    android:id="@+id/txtitems" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_below="@id/editadd" 
    android:text="Item(s): " 
    /> 
<EditText 
    android:id="@+id/edititems" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_below="@id/txtadd" 
    android:hint="Enter item(s) here" 
    /> 
<Button 
    android:id="@+id/btn_submit" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_below="@id/edititems" 
    android:text="Submit form" 
    /> 
</TableLayout> 

यहाँ मेरी जावा वर्ग कोड

public class OrderFormActivity extends Activity implements OnClickListener{ 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.orderform); 

    Button btnsubmit = (Button)findViewById(R.id.btn_submit); 
    btnsubmit.setOnClickListener(this); 
} 

@Override 
public void onClick(View v) { 
    // TODO Auto-generated method stub 
    if (v == this.findViewById(R.id.btn_submit)) { 

    EditText name = (EditText)findViewById(R.id.editname); 
    String strname = name.getText().toString(); 

    EditText email = (EditText)findViewById(R.id.editemail); 
    String stremail = email.getText().toString(); 

    EditText num = (EditText)findViewById(R.id.editnum); 
    String strnum = num.getText().toString(); 

    EditText add = (EditText)findViewById(R.id.editadd); 
    String stradd = add.getText().toString(); 

    EditText items = (EditText)findViewById(R.id.edititems); 
    String stritems = items.getText().toString(); 

    showOrder(strname, stremail, strnum, stradd,stritems); 
    } 

} 

private void showOrder (String strname, String stremail, String strnum, String stradd, String stritems) { 
    String result = strname + stremail + strnum + stradd + stritems; 

    //Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND); 

    String emailAddress = "[email protected]"; 

    Intent intent = new Intent(Intent.ACTION_SEND); 
    intent.setType("plain/text"); 
    intent.putExtra(Intent.EXTRA_EMAIL, emailAddress);  
    intent.putExtra(Intent.EXTRA_TEXT, result);   

} 

}

धन्यवाद एक है अग्रिम में फिर से होगा !!! : डी

+0

एंड्रॉइड का उपयोग करें: बटन पर एक्सएमएल पर क्लिक करें और फिर बटन क्लिक के लिए एक फ़ंक्शन बनाएं। तो आपको v == ... – trgraglia

+3

के लिए उस परीक्षण की आवश्यकता नहीं है http://stackoverflow.com/questions/2020088/sending-email-in-android-using-javamail-api-without-using-the-default-android -एप – PearsonArtPhoto

+0

त्वरित प्रतिक्रिया के लिए सभी को धन्यवाद। -trgraglia, मुझे लगता है कि यह मुख्य समस्या नहीं है क्योंकि अब मैं जो करने की कोशिश कर रहा हूं वह सभी बटन इनपुट को केवल एक बटन की मदद से एक विशिष्ट ईमेल पते पर कैप्चर करना है। -Pearsonartphoto, उत्तर के लिए धन्यवाद, हालांकि, ऐसा करने में एक छोटा रास्ता है? क्योंकि मैंने पाया कि समाधान बहुत बोझिल .. क्षमा करें! – Winona

उत्तर

2

उपयोगकर्ता इंटरैक्शन के बिना इरादे के माध्यम से ईमेल भेजने के लिए कोई एपीआई नहीं है। एसओ में इसे कई बार दोहराया गया है।

जैसा कि पियरसनर्टफोटो ने सुझाव दिया है, आपको ईमेल भेजने के लिए बाहरी पुस्तकालय का उपयोग करने की आवश्यकता है। जावामेल स्पष्ट पहला विकल्प है, भले ही आपने "समाधान बहुत बोझिल पाया"।

तो आपको पोस्ट किए गए सभी फ़ील्ड एकत्र करने की आवश्यकता है, ईमेल के लिए उपयोगी तरीके से प्रारूपित करें (शायद एक्सएमएल, शायद JSON?) और इसे जावामेल के साथ टेक्स्ट के रूप में भेजें।

+0

या बस अपने स्वयं के वेब सर्वर पर एक पोस्ट अनुरोध भेजें जो संभवतः PHP चला रहा है और – binnyb

+0

मेल भेजने के लिए 'मेल' फ़ंक्शन का उपयोग करें हाय, आपकी प्रतिक्रिया के लिए धन्यवाद। हालांकि, मुझे अभी भी जावामेल का उपयोग करने और उपयोगकर्ता के लिए फ़ील्ड एकत्र करने के लिए xml का उपयोग करने के बारे में संदेह है। :/पूरी तरह खो गया है और कहीं भी नहीं जा रहा है ... – Winona

+0

@ विनोना आप एक सरल समाधान के लिए एक्सएमएल के बजाय जेएसओएन का उपयोग कर सकते हैं। जीएसओएन या org.json पुस्तकालयों का प्रयास करें। – Aleadam

संबंधित मुद्दे