我试图通过Android的电子邮件客户端发送电子邮件。但是,当我尝试将电子邮件发送到客户端时,它表示电子邮件为空。我发现这很奇怪,因为我在JavaScript中传递了正确的参数,但应用程序不会读取它?
我一直在研究这个问题已经有一段时间了,并且已经搜索了Stack Overflow一段时间了。
无论如何,我的目标是了解为什么我的参数没有通过。
JavaScript的:
function sendEmailToAndroid (emailAddresses, CC, subject) {
alert(emailAddresses); //This displays the correct address
if (IsAndroidDevice()) {
window.ccs.sendEmail(emailAddresses, CC, subject);
}
}
爪哇:
@JavascriptInterface
public void sendEmail(String[] emailAddress, String[] CC, String subject){
Intent email = new Intent(Intent.ACTION_SEND);
email.putExtra(Intent.EXTRA_EMAIL, emailAddress);
email.putExtra(Intent.EXTRA_CC, CC);
email.putExtra(Intent.EXTRA_SUBJECT, subject);
email.setType("message/rfc822");
if(emailAddress == null || emailAddress.length == 0){
Toast ctoast = Toast.makeText(getApplicationContext(), "There is no email for this customer", Toast.LENGTH_LONG);
ctoast.setGravity(Gravity.CENTER, 0, 0);
ctoast.show();
Log.d(LOG, "Email: "+emailAddress);
}
else{
try{
startActivity(Intent.createChooser(email, "Send mail..."));
} catch(ActivityNotFoundException e){
Toast.makeText(getApplicationContext(), "Failed to initalize email client!", Toast.LENGTH_LONG).show();
}
}
}
现在,当我调试JavaScript时,所有参数都正确传递。但是,当在Android应用程序中读取它时,所有值都返回null或undefined。哪个不对。