2017-12-13 16 views
0

그래서 앱을 이메일로 보낼 수있게 만들었지 만 팝업 콘텐츠로 대화 상자를 부 풀릴 때 보내기 버튼이 더 이상 작동하지 않습니다. 사용자가 앱을 여러 번 열면 팝업이 표시됩니다. 몇 가지 질문) 오순절이메일 보내기 - 방법?

내 메일 코드 : 그것은 내부에 (PopUp.java) : 이것이 내가 몇 번을 대화의 팽창기를하고 계산 내 FeedBack.java을 (이다

public class PopUp extends AppCompatActivity implements View.OnClickListener{ 
private EditText editTextEmail; 
private EditText editTextSubject; 
private EditText editTextMessage; 
private Button buttonSend; 
@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_pop_up); 


    editTextEmail = (EditText) findViewById(R.id.editTextEmail); 
    editTextSubject = (EditText) findViewById(R.id.editTextSubject); 
    editTextMessage = (EditText) findViewById(R.id.editTextMessage); 

    buttonSend = (Button) findViewById(R.id.buttonSend); 

    //this is the button for sending the email 
    buttonSend.setOnClickListener(this); 
} 


private void sendEmail() { 
    String email = editTextEmail.getText().toString().trim(); 
    String subject = editTextSubject.getText().toString().trim(); 
    String message = editTextMessage.getText().toString().trim(); 
    SendMail sm = new SendMail(this, email, subject, message); 

    sm.execute(); 
} 

@Override 
public void onClick(View v) { 
    sendEmail(); 
} 
} 

응용 프로그램이 열렸습니다.) 여기에 문제가 있습니다 (대화 상자가 모든 버튼/텍스트 편집). 버튼을 누르면 메일이 전송되지 않습니다.

,210
private SharedPreferences prefs; 
private SharedPreferences.Editor editor; 
private int totalCount; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_feed_back); 
    prefs = getPreferences(Context.MODE_PRIVATE); 
    editor = prefs.edit(); 

    totalCount = prefs.getInt("counter", 0); 
    totalCount++; 
    editor.putInt("counter", totalCount); 
    editor.commit(); 



    if (totalCount == 2) 
    { 
     dialog(); 
    } 

} 

private void dialog() { 
    final View viewPop = LayoutInflater.from(FeedBack.this).inflate(R.layout.activity_pop_up , null); 


    AlertDialog.Builder alertBuilder = new AlertDialog.Builder(this); 
    alertBuilder.setMessage("Feedback!") 
      .setView(viewPop) 
      .setPositiveButton("Send!", new DialogInterface.OnClickListener() { 
       @Override 
       public void onClick(DialogInterface dialogInterface, int i) { 
        //i've tryed to call the function here but i dropped the idea because i didn't know how to call an method from another java file :(
       } 
      }) 
      .setNegativeButton("Cancel!", new DialogInterface.OnClickListener() { 
       @Override 
       public void onClick(DialogInterface dialogInterface, int i) { 
        Toast.makeText(getApplicationContext(), "Canceled!", Toast.LENGTH_LONG).show(); 
       } 
      }).show(); 
} 

그리고이 전자 우편 전송에 대한 코드입니다 :

private void sendMail() { 
    //Getting content for email 
    String email = editTextEmailValue.getText().toString().trim(); 
    String subject = editTextSubjectValue.getText().toString().trim(); 
    String message = editTextMessageValue.getText().toString().trim(); 

    //Creating SendMail object 
    SendMail sm = new SendMail(this, email, subject, message); 

    //Executing sendmail to send email 
    sm.execute(); 
} 

과 : 그것은 내가 .setPosstiveButton에 전화를 넣어하는 방법으로이 같은 짓 작동 이제

public class SendMail extends AsyncTask<Void,Void,Void> { 

    //Declaring Variables 
    private Context context; 
    private Session session; 

    //Information to send email 
    private String email; 
    private String subject; 
    private String message; 
    private String nume; 

    //Progressdialog to show while sending email 
    private ProgressDialog progressDialog; 

    //Class Constructor 
    public SendMail(Context context, String email, String subject, String message){ 
     //Initializing variables 
     this.context = context; 
     this.nume = nume; 
     this.email = email; 
     this.subject = subject; 
     this.message = message; 
    } 

    @Override 
    protected void onPreExecute() { 
     super.onPreExecute(); 
     //Showing progress dialog while sending email 
     progressDialog = ProgressDialog.show(context,"Sending message","Please wait...",false,false); 
    } 

    @Override 
    protected void onPostExecute(Void aVoid) { 
     super.onPostExecute(aVoid); 
     //Dismissing the progress dialog 
     progressDialog.dismiss(); 
     //Showing a success message 
     Toast.makeText(context,"Message Sent",Toast.LENGTH_LONG).show(); 
    } 

    @Override 
    protected Void doInBackground(Void... params) { 
     //Creating properties 
     Properties props = new Properties(); 

     //Configuring properties for gmail 
     //If you are not using gmail you may need to change the values 
     props.put("mail.smtp.host", "smtp.gmail.com"); 
     props.put("mail.smtp.socketFactory.port", "465"); 
     props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory"); 
     props.put("mail.smtp.auth", "true"); 
     props.put("mail.smtp.port", "465"); 

     //Creating a new session 
     session = Session.getDefaultInstance(props, 
       new javax.mail.Authenticator() { 
        //Authenticating the password 
        protected PasswordAuthentication getPasswordAuthentication() { 
         return new PasswordAuthentication(Config.EMAIL, Config.PASSWORD); 
        } 
       }); 

     try { 
      //Creating MimeMessage object 
      MimeMessage mm = new MimeMessage(session); 

      //Setting sender address 
      mm.setFrom(new InternetAddress(Config.EMAIL)); 
      //Adding receiver 
      mm.addRecipient(Message.RecipientType.TO, new InternetAddress(email)); 
      //Adding subject 
      mm.setSubject(subject); 
      //Adding message 
      mm.setText(message); 

      //Sending email 
      Transport.send(mm); 

     } catch (MessagingException e) { 
      e.printStackTrace(); 
     } 
     return null; 
    } 
+0

당신이 MessagingException의를받을 수 있나요? – petey

+0

나는 이것을 할 수 있었다 :) @petey와 나는 어떻게 내가 아래에했다라고 게시했다. –

답변

0

을 추가 한 내용 :

final View viewPop = LayoutInflater.from(FeedBack.this).inflate(R.layout.activity_pop_up, null); 
    editTextEmailValue = (EditText) viewPop.findViewById(R.id.editTextEmail); 
    editTextSubjectValue = (EditText) viewPop.findViewById(R.id.editTextSubject); 
    editTextMessageValue = (EditText) viewPop.findViewById(R.id.editTextMessage); 

대화 방법

과 선언 :

private EditText editTextEmailValue; 
private EditText editTextSubjectValue; 
private EditText editTextMessageValue;