1

したがって、これでユーザーからの入力をメールで送信したいのですが、ユーザーがメールアプリを選択して「宛先」アドレスを手動で入力する必要はありません。何をすべきかわからない。

現在、すべての入力が保存されますが、ユーザーはメール クライアントを選択する必要があり、「宛先」フィールドは事前入力されません。

package com.rappe.refillsapp;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.Button;
import android.content.Intent;

public class RefillActivity extends Activity {
    public String name;
    public String birthday;
    public String prescriptionOptions;
    public String notes;
    public String number;
    public String email;


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.refill_activity_main);

    Button submit = (Button) findViewById(R.id.ButtonSendRefillRequest);
    submit.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            sendRefillRequest();
            String to = email;
            String subject = name;
            String message = (birthday+"\n"+number+"\n"+prescriptionOptions+"\n"+notes);

            Intent mEmail = new Intent(Intent.ACTION_SEND);
            mEmail.putExtra(Intent.EXTRA_EMAIL, to);
            mEmail.putExtra(Intent.EXTRA_SUBJECT, subject);
            mEmail.putExtra(Intent.EXTRA_TEXT, message);

            //lets user choose email client/app
            mEmail.setType("message/rfc822");
            startActivity(Intent.createChooser(mEmail, "Choose an email client to send your request for a refill!"));

        }
    });
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.refill, menu);
    return true;
}
public void sendRefillRequest(){
    final EditText nameField = (EditText) findViewById(R.id.EditTextName);
    name = nameField.getText().toString();
    final EditText birthdayField = (EditText) findViewById(R.id.EditTextBirthday);
    birthday =  birthdayField.getText().toString();
    final EditText numberField = (EditText) findViewById(R.id.EditTextPrescriptionNumber);
    number = numberField.getText().toString();
    final Spinner prescriptionOptions = (Spinner) findViewById(R.id.SpinnerPrescriptionOptions);
    this.prescriptionOptions = prescriptionOptions.getSelectedItem().toString();
    final EditText notesField = (EditText) findViewById(R.id.EditTextSpecialNotes);
    notes = notesField.getText().toString();



}

}

4

1 に答える 1

1

編集...この質問はこれを行う方法を提供しますが、いくつかの尊敬されるポスターは、これらの手法は文書化されていないと指摘しています...

Intentを使用してメールを送信できます。

Intent sendIntent = new Intent(Intent.ACTION_SEND);
String subject = "My subject";
String body = "My body text";
sendIntent.setType("message/rfc822");
sendIntent.putExtra(Intent.EXTRA_EMAIL, new String[] { "recipient.address@xyz.com" });
sendIntent.putExtra(Intent.EXTRA_TEXT, body);
sendIntent.putExtra(Intent.EXTRA_SUBJECT, subject);
sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File("/file/to/attach")));
startActivity(Intent.createChooser(sendIntent, "Please send email"));

hereを呼び出していることに注意してChooserください。

于 2013-08-26T02:05:04.333 に答える