2013-08-26 64 views
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(); 



} 

}

+0

在這種情況下,您的數據提交到一個PHP腳本,並轉發到他們的郵件地址! –

回答

1

編輯...這Question給出這樣做的方法,但一些尊敬的海報指出,這些技術都是無證...

我們可以使用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[] { "[email protected]" }); 
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")); 

注意,我調用這裏的Chooser

+0

那麼這會發送電子郵件而不提示選擇? – coltsfan95

+0

不......這就是爲什麼我說我會更新或刪除...順便說一句,不給用戶一個選擇不建議。 – andy256

+0

這不是我根本不想給他們一個選擇,我只是不想公開目標電子郵件地址。 – coltsfan95

相關問題