getDefaultInstance和javax.mail.session的问题,java.io.inputstream

发布于 2025-02-11 03:23:22 字数 1187 浏览 2 评论 0 原文

我正在寻找这两个错误的答案,但没有找到解决方案。

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!");
        }

I have looking around for answer to these two errors, and have not found the solution.

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)'

Am I missing something as to using the package?

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

滿滿的愛 2025-02-18 03:23:22

您的会话导入是错误的。用 android.se.omapi.session javax.mail.mail.session 替换导入。如果这会导致其他问题,因为您需要两个导入,那么对于其中一个就需要使用完全合格的名称。例如:

javax.mail.Session session = javax.mail.Session.getDefaultInstance(properties, null);

另一个问题是 uri 参数。没有 Mimemessage 构造函数,它可以采用 uri uri 参数。我认为您有现有消息作为文件,并且想从中阅读。您需要将 uri 转换为 inputstream 。我在。我会看看您是否可以完全摆脱 uri 参数,并用 inputStream 或可以将其转换为 InputStream 的东西替换。 。

Your Session import is the wrong one. Replace the import for android.se.omapi.Session with javax.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:

javax.mail.Session session = javax.mail.Session.getDefaultInstance(properties, null);

The other issue is the Uri argument. There is no MimeMessage constructor that takes a URI or Uri argument. I assume that you have an existing message as a file and want to read from it. You'd need to convert the Uri to an InputStream. 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 the Uri argument completely and replace it with an InputStream or something that can be converted to an InputStream.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文