我正在尝试通过单击按钮发送电子邮件,发送邮件是用户给出的识别码。但电子邮件未正确发送。任何人都可以帮我解决这个问题。
我根据这个创建了我的应用程序: -
Sending Email in Android using JavaMail API without using the default/built-in app
这是我得到的logcat消息。
03-16 01:51:13.592 1913-1913/com.example.dushani.emailsender I/art﹕ Not late-enabling -Xcheck:jni (already on)
03-16 01:51:13.688 1913-1928/com.example.dushani.emailsender D/OpenGLRenderer﹕ Render dirty regions requested: true
03-16 01:51:13.711 1913-1913/com.example.dushani.emailsender D/﹕ HostConnection::get() New Host Connection established 0xae2eadc0, tid 1913
03-16 01:51:13.724 1913-1913/com.example.dushani.emailsender D/Atlas﹕ Validating map...
03-16 01:51:13.750 1913-1925/com.example.dushani.emailsender I/art﹕ Background sticky concurrent mark sweep GC freed 1795(95KB) AllocSpace objects, 0(0B) LOS objects, 35% free, 402KB/623KB, paused 16.584ms total 23.060ms
03-16 01:51:13.909 1913-1928/com.example.dushani.emailsender D/﹕ HostConnection::get() New Host Connection established 0xa6e3f3f0, tid 1928
03-16 01:51:13.925 1913-1928/com.example.dushani.emailsender I/OpenGLRenderer﹕ Initialized EGL, version 1.4``
03-16 01:51:13.999 1913-1925/com.example.dushani.emailsender I/art﹕ Background partial concurrent mark sweep GC freed 1958(107KB) AllocSpace objects, 0(0B) LOS objects, 53% free, 436KB/948KB, paused 1.878ms total 189.812ms
03-16 01:51:14.019 1913-1928/com.example.dushani.emailsender D/OpenGLRenderer﹕ Enabling debug mode 0
03-16 01:51:14.043 1913-1928/com.example.dushani.emailsender W/EGL_emulation﹕ eglSurfaceAttrib not implemented
03-16 01:51:14.044 1913-1928/com.example.dushani.emailsender W/OpenGLRenderer﹕ Failed to set EGL_SWAP_BEHAVIOR on surface 0xa6e0df20, error=EGL_SUCCESS
03-16 01:51:47.305 1913-1928/com.example.dushani.emailsender W/EGL_emulation﹕ eglSurfaceAttrib not implemented
03-16 01:51:47.305 1913-1928/com.example.dushani.emailsender W/OpenGLRenderer﹕ Failed to set EGL_SWAP_BEHAVIOR on surface 0xa6e0df20, error=EGL_SUCCESS
03-16 01:52:30.073 1913-1925/com.example.dushani.emailsender I/art﹕ Background sticky concurrent mark sweep GC freed 1881(109KB) AllocSpace objects, 0(0B) LOS objects, 23% free, 723KB/948KB, paused 1.427ms total 111.164ms
答案 0 :(得分:2)
我使用这种方法,
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("message/rfc822");
String possibleEmail = new String();
mailArray = new String[]{getString(R.string.mail), possibleEmail};
Pattern emailPattern = Patterns.EMAIL_ADDRESS;
Account[] accounts = AccountManager.get(getBaseContext()).getAccounts();
for (Account account : accounts) {
if (emailPattern.matcher(account.name).matches()) {
possibleEmail = account.name;
}
}
if(sendToMeCheckBox.isChecked()){
mailArray [1] = possibleEmail;
}
intent.putExtra(Intent.EXTRA_EMAIL, mailArray );
intent.putExtra(Intent.EXTRA_SUBJECT, "Some random subject");
intent.putExtra(Intent.EXTRA_TEXT, "Some random text");
try {
startActivity(Intent.createChooser(intent, "Send email..."));
} catch (Exception e) {
Toast.makeText(this, "There are no mail applications on the device!", Toast.LENGTH_LONG).show();
}
}