2013-08-26 1 views
1

그래서 사용자의 전자 메일을 나에게 보내주기를 원하지만 사용자가 전자 메일 앱을 선택하고 수동으로 "받는 사람"주소를 입력하지 않아도되도록하고 싶습니다. 무엇을해야할지 모르겠습니다.사용자로부터 피드백 입력을 받아 전자 메일을 보내는 앱을 만들려고합니다. 아이디어?

현재 모든 입력 내용을 저장하지만 사용자가 전자 메일 클라이언트를 선택하게하고 "받는 사람"필드를 미리 채우지 않습니다.

우리는 Intent을 사용하여 이메일을 보낼 수 있습니다 ...

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이 일의 방법을 제공하지만, 여러 존경 포스터는 이러한 기술을 문서화하는 것을 지적 : 내가 여기 Chooser를 호출입니다

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

주 .

+0

이렇게하면 선택 메시지가 표시되지 않고 이메일이 전송됩니까? – coltsfan95

+0

아니요 ... 그 이유는 내가 업데이 트하거나 삭제할 것입니다 ... BTW, 사용자에게 선택권을주지 않는 것은 권고하지 않습니다. – andy256

+0

나는 그 (것)들에게 선택권을주고 싶지 않다, 단순히 목적지 전자 우편 주소를 드러내고 싶지 않다. – coltsfan95

관련 문제