2011-06-06 15 views
5

私は現在、注文フォームを持つAndroidアプリケーションを開発中です。私はどのようにアプリケーションが電子メールのアプリケーションページにユーザーを持って来ることなく、ユーザーが入力したものをキャプチャし、ボタンを使用して電子メールに直接送信することをアプリケーションに許可することができます。私の.javaクラスにはエラーがありますが、私は試しています...以下は私のxml(レイアウト)ファイルと私の.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> 

が私の.javaクラスコード

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);   

} 

}

のおかげである。aは、再び前倒し! :D

+0

android:onを使用してボタンのXMLをクリックし、ボタンをクリックする機能を作成します。あなたはv ==のためのそのテストが必要ないです... – trgraglia

+3

参照してくださいhttp://stackoverflow.com/questions/2020088/sending-email-in-android-using-javamail-api-without-using-the-default-android -app – PearsonArtPhoto

+0

クイックレスポンスに感謝します。 -trgraglia、私は主な問題ではないと思います。なぜなら、今私がしようとしているのは、ボタンの助けを借りてすべてのユーザー入力を特定のメールアドレスにキャプチャする電子メールを送信することです。 -Pearsonartphoto、答えをいただきありがとうございます。私はそのソリューションが面倒すぎることを発見したので、..ごめんなさい! – Winona

答えて

2

ユーザーインタラクションなしでインテントを通じてメールを送信するAPIはありません。これはここで数回繰り返されています。

pearsonartphotoが示唆しているように、電子メールを送信するには外部ライブラリを使用する必要があります。そのソリューションがあまりにも面倒であったとしても、JavaMailは最初の選択肢です。

投稿したときにすべてのフィールドを収集する必要があります。電子メール(おそらくXML、おそらくJSON?)に便利な形式で書式を設定し、JavaMailでテキストとして送信します。

+0

か、ちょうどPHPを実行している自分のWebサーバーに投稿要求を送信し、メールを送信するために 'mail'関数を使用してください。 – binnyb

+0

こんにちは、ありがとうございます。しかし、私はJavaMailの使い方とxmlを使ってユーザのフィールドを収集する方法について疑問を抱いています。 :/完全に失われてどこにも向かない... – Winona

+0

@Winonaもっと簡単な解決策として、XMLの代わりにJSONを使うことができます。 GSONまたはorg.jsonライブラリを試してみてください。 – Aleadam

関連する問題