2017-12-13 10 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(); 
} 
} 

アプリが開かれた)ここに問題がある(ダイアログはすべてのボタンを表示/テキストを編集する)が、ボタンを押すとメールは送信されない:

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

そして、これは、電子メールを送信するためのコードです:

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

今では私は.setPosstiveButtonで、私はこのようにやった方法で呼び出しを入れて動作します:

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

と私はこれを追加しました:

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; 
関連する問題