getDefaultInstance和javax.mail.session的问题,java.io.inputstream
我正在寻找这两个错误的答案,但没有找到解决方案。
Cannot resolve method 'getDefaultInstance' in 'Session'
'MimeMessage(javax.mail.Session, java.io.InputStream)' in 'javax.mail.internet.MimeMessage' cannot be applied to '(android.se.omapi.Session, android.net.Uri)'
我是否缺少使用包裹的东西?
public void getBodySignature(Uri uri) throws Exception {
Properties properties = System.getProperties();
Session session = Session.getDefaultInstance(properties, null);
MimeMessage msg = new MimeMessage(session, uri);
SMIMESigned signedMessage;
// multipart/signed message
// two parts- one part for the content that was signed and one part for the actual signature.
if (msg.isMimeType("multipart/signed")) {
signedMessage = new SMIMESigned((MimeMultipart) msg.getContent());
} else if (msg.isMimeType("text/plain") || msg.isMimeType("application/pkcs7-signature")) {
// in this case the content is wrapped in the signature block.
signedMessage = new SMIMESigned(msg);
} else {
throw new IllegalArgumentException("Not a signed message!");
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的
会话
导入是错误的。用android.se.omapi.session
javax.mail.mail.session
替换导入。如果这会导致其他问题,因为您需要两个导入,那么对于其中一个就需要使用完全合格的名称。例如:另一个问题是
uri
参数。没有Mimemessage
构造函数,它可以采用uri
或uri
参数。我认为您有现有消息作为文件,并且想从中阅读。您需要将uri
转换为inputstream
。我在。我会看看您是否可以完全摆脱uri
参数,并用inputStream
或可以将其转换为InputStream
的东西替换。 。Your
Session
import is the wrong one. Replace the import forandroid.se.omapi.Session
withjavax.mail.Session
. If that causes other issues, because you need both imports, then for one of them you to use the fully qualified name. For instance:The other issue is the
Uri
argument. There is noMimeMessage
constructor that takes aURI
orUri
argument. I assume that you have an existing message as a file and want to read from it. You'd need to convert theUri
to anInputStream
. I couldn't find anything for that in https://developer.android.com/reference/android/net/Uri. I'd see if you can get rid of theUri
argument completely and replace it with anInputStream
or something that can be converted to anInputStream
.