在Android中无法获得使用Java发送电子邮件的确认?

时间:2014-01-22 05:31:35

标签: java android email

我是android的新手。我写了这段代码,工作正常并发送电子邮件,但是当我按下提交按钮时,它会在选择“时打开”选择电子邮件客户端“ GMAIL “它打开gmail帐户并发送并显示Toast消息”发送消息“并且电子邮件成功发送到目的地地址,我仍在”电子邮件屏幕“是否有任何方法可以检查电子邮件是否已到达目的地地址成功它返回“true”,否则它返回“false”,以便在该布尔值的基础上,我可以在所有编辑框上设置空值或刷新所有文本框。

    ImageView submitBtn = (ImageView)findViewById(R.id.askscreen_submit_btn);
            submitBtn.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    // TODO Auto-generated method stub
                try {
    // CALL GetText method to make post method call
                        //GetText();
                SendEmailToAalim(email.getText().toString(),name.getText().toString(),address.getText().toString(),subject.getText().toString());
                } catch (Exception ex) {
                        content.setText(" url exeption! ");
                    }   
                }
            });
        }
        public void SendEmailToAalim(String email,String name,String address,String subject)
        {
            if(email == null || email.length()==0)
            {
            Toast.makeText(context,"Please Enter Email Id",Toast.LENGTH_LONG).show();
            }
            else if(email.length()>0 && email!= null && !checkEmailValidity(email))
            {
                Toast.makeText(context,"Please Enter Correct Email Id",Toast.LENGTH_LONG).show();

            }
            else if(subject == null || subject.length() == 0)
            {
                Toast.makeText(context,"Please Enter Value in Subject",Toast.LENGTH_LONG).show();   
            }
            else if(name == null || name.length() ==0)
            {
                Toast.makeText(context,"Please Enter Value in Name Field",Toast.LENGTH_LONG).show();    
            }
            else if(address == null || address.length() ==0)
            {
                Toast.makeText(context,"Please Enter Value in Address Field",Toast.LENGTH_LONG).show();
            }
            else if(email.length()!= 0 &&  checkEmailValidity(email) == true &&subject.length()!=0 && address.length()!=0 && name.length()!=0)
            {
                Intent emailSendIntent = new Intent(Intent.ACTION_SEND); 
                emailSendIntent.putExtra(Intent.EXTRA_EMAIL,new String[]{"abc32@yahoo.com"}); 
    emailSendIntent.putExtra(Intent.EXTRA_SUBJECT, subject); 
   emailSendIntent.setType("message/rfc822");
    //emailSendIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // this will make such that when user returns to your app, your app is displayed, instead of the email app.
    startActivity(Intent.createChooser(emailSendIntent,"Choose an Email client :"));    
  }
  }
 public static boolean checkEmailValidity(CharSequence email)
 {
  return android.util.Patterns.EMAIL_ADDRESS.matcher(email).matches(); 
 }

这是电子邮件屏幕的屏幕截图。有人请指出我应该做些什么来提醒用户已发送电子邮件并刷新页面。

Email Screen

1 个答案:

答案 0 :(得分:0)

try to use these ::->


final Intent intent = new Intent(
                            android.content.Intent.ACTION_SEND);
                    intent.setType("*/*");
                    intent.putExtra(android.content.Intent.EXTRA_SUBJECT,
                            "");
                    intent.putExtra(android.content.Intent.EXTRA_STREAM,
                            Uri.fromFile(new File("file name")));
                    final PackageManager pm = getPackageManager();
                    final List<ResolveInfo> matches = pm.queryIntentActivities(
                            intent, 0);
                    ResolveInfo best = null;
                    for (final ResolveInfo info : matches)
                        if (info.activityInfo.packageName.endsWith(".gm")
                                || info.activityInfo.name.toLowerCase()
                                        .contains("gmail"))
                            best = info;
                    if (best != null)
                        intent.setClassName(best.activityInfo.packageName,
                                best.activityInfo.name);
                    startActivity(intent);