我查了一下,这是发送电子邮件的最常见方式......
Intent i = new Intent(Intent.ACTION_SEND);
i.setType("message/rfc822");
i.putExtra(Intent.EXTRA_EMAIL , new String[]{"recipient@example.com"});
i.putExtra(Intent.EXTRA_SUBJECT, "subject of email");
i.putExtra(Intent.EXTRA_TEXT , "body of email");
try {
startActivity(Intent.createChooser(i, "Send mail..."));
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(MyActivity.this, "There are no email clients
installed.",
Toast.LENGTH_SHORT).show();
}
我对这实际发送的内容感到困惑,以及如何在用户点击按钮时实现这一点。我把收件人的电子邮件(我)这样吗?
i.putExtra(Intent.EXTRA_EMAIL , "myemail@gmail.com");
然后电子邮件的主题和消息/正文的格式相同?
这是我将用户的输入放入电子邮件正文的方式吗? (用户输入多个editText框)
editText userTitle = (editText)findViewById(R.id.idOfTheEditTextBox);
editText userDescription = (editText)findViewById(R.id.idOfTheEditTextBox);
然后像这样输入?
i.putExtra(Intent.EXTRA_TEXT , "userTitle", "userDescription");
最后,所有吐司和没有安装电子邮件客户端的意思是什么?我是Android应用程序开发的新手,我正在Android Studio上制作应用程序!非常感谢所有帮助!!谢谢!
答案 0 :(得分:3)
首先“ Toast ”
编写Toast代码是为了向用户发出警报,通知没有电子邮件 客户端可在用户手机中使用(例如gmail等)
现在是主要部分,
i.putExtra(Intent.EXTRA_EMAIL , new String[]{"recipient@example.com"});
是的,上面的行添加了配方电子邮件地址。
因此,为了实现这一点,您需要做以下事情,
public class MainActivity extends AppCompatActivity {
EditText etRecipentId, etSubject, etBody;
Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
etRecipentId = (EditText) findViewById(R.id.email_id);
etSubject = (EditText) findViewById(R.id.et_subject);
etBody = (EditText) findViewById(R.id.et_body);
}
b1.setOnClickListener(new OnClickListener() {
public void onClick() {
Intent i = new Intent(Intent.ACTION_SEND);
i.setType("message/rfc822");
i.putExtra(Intent.EXTRA_EMAIL, new String[] {
etRecipentId.getText().toString();
});
i.putExtra(Intent.EXTRA_SUBJECT, etSubject.getText().toString(););
i.putExtra(Intent.EXTRA_TEXT, etBody.getText().toString(););
try {
startActivity(Intent.createChooser(i, "Send mail..."));
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(MyActivity.this, "There are no email clients
installed.",
Toast.LENGTH_SHORT).show();
}
}
});
答案 1 :(得分:0)
而不是<?php echo form_open('reg_ctrl/send_validation_email', array('class' => 'form-horizontal','role' => 'form'));?>
<div class="form-group has-feedback">
<label for="inputUserName" class="col-sm-4 control-label">User Name <span class="text-danger small">*</span></label>
<div class="col-sm-8">
<?php echo form_input(array('class'=>'form-control','type'=>'text','required'=>'email', 'id' => 'user_name', 'name' => 'user_name', 'placeholder' => 'User Name')); ?><i class="fa fa-user form-control-feedback"></i>
</div>
</div>
<div class="form-group has-feedback">
<label for="inputEmail" class="col-sm-4 control-label">Email <span class="text-danger small">*</span></label>
<div class="col-sm-8">
<?php echo form_input(array('class'=>'form-control','type'=>'email','required'=>'email', 'id' => 'email', 'name' => 'email', 'placeholder' => 'Email')); ?><i class="fa fa-envelope form-control-feedback"></i>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-4 col-sm-8">
<button type="submit" class="btn btn-group btn-default btn-animated">Sign Up <i class="fa fa-check"></i></button>
</div>
</div>
<?php echo form_close(); ?>
使用i.putExtra(Intent.EXTRA_TEXT , "userTitle", "userDescription");
当您遇到异常时,请检查手机中是否安装了gmail等电子邮件客户端。