android - java.lang.VerfyError:在 Android 11 中发送电子邮件
问题描述
我写了一个从我的应用程序发送电子邮件的方法。此方法在所有版本的 Android 中都能完美运行,除了 Andorid 11。这是我在 Grandle 中的实现:
implementation 'com.sun.mail:android-mail:1.6.0'
implementation 'com.sun.mail:android-activation:1.6.0'
这是我发送电子邮件的方法:
public static boolean send(String oggetto, String testo, String[] dests) {
Properties properties = new Properties();
properties.put("mail.smtp.auth", "true");
properties.put("mail.smtp.starttls.enable", "true");
properties.put("mail.smtp.host", "smtp.gmail.com");
properties.put("mail.smtp.port", "587");
Session session = Session.getInstance(properties, new Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(USERNAME, PASSWORD);
}
});
Message message = new MimeMessage(session);
final boolean[] send = new boolean[1];
final boolean[] loading = {false};
try {
message.setFrom(new InternetAddress(USERNAME));
InternetAddress[] addressTo = new InternetAddress[dests.length];
for (int i = 0; i < dests.length; i++)
{
addressTo[i] = new InternetAddress(dests[i]);
}
message.setRecipients(Message.RecipientType.TO, addressTo);
message.setSubject(oggetto);
message.setText(testo);
new Thread(new Runnable() {
@Override
public void run() {
try {
Transport.send(message);
loading[0] = true;
send[0] = true;
} catch (MessagingException e) {
loading[0] = true;
send[0] = false;
}
}
}).start();
} catch (MessagingException e) {
return false;
}
while (!loading[0]) {}
return send[0];
}
这是 Android 11 中的日志错误:
java.lang.VerifyError: Rejecting class com.sun.mail.handlers.text_plain that attempts to sub-type erroneous class com.sun.mail.handlers.handler_base
解决方案
推荐阅读
- android - 更新 Android TableLayout 中 TextView 的内容
- wpf - 用于颜色选择器的 WPF 双渐变
- jquery - 使用 jquery 关闭模式显示窗口
- android - 为什么总是应用程序因违反政策而被拒绝且未发布:
- mysql - MySQL根据SUM列别名计算2列之间的百分比差异(不改变)
- flash - 我如何编辑 swf 文件的动作脚本
- ios - 如何将flutter创建的IOS项目连接到firebase?
- java - 如何将图像添加到 JFrame 的标题栏?
- ionic-framework - 离子项目选项不显示
- c++ - 如何在 C++ 中为每个应用程序播种一次 mt19937 并多次使用?