使用 Smack XMPP 发送内嵌图像 [英] Sending inline images using Smack XMPP

查看:45
本文介绍了使用 Smack XMPP 发送内嵌图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将要创建一个简单的 xmpp java 客户端应用程序,为此我正在考虑使用 Smack XMPP 库,它运行良好.

I am about to create a simple xmpp java client application and for this I am considering to use the Smack XMPP library, which works pretty well.

客户端的一个功能应该是向您的聊天伙伴发送内嵌图像.我浏览了 SMACK 的 javadoc,但我无法找到如何使用 SMACK/XMPP 发送图像或一般的二进制数据.我不是在谈论接收用户必须接受的标准文件传输,而是可以在消息中发送的图像.这可以用 SMACK/XMPP 实现吗?谁能举个例子?

One feature of the client should be to send inline images to your chatpartner. I browsed through the javadoc of SMACK but I was not able to find how it's possible to send images or in general binary data with SMACK/XMPP. I am not talking about a standard file transfer that the receiving user has to accept, but rather an image which can be sent within a message. Is this possible with SMACK/XMPP? Can anybody provide an example?

推荐答案

您可以使用 smth 使其默认接受(不会提示用户):

You can just make it accepted by default (the user won't be prompted) by using smth like:

final FileTransferManager manager = new FileTransferManager(connection); //Use your xmpp connection
manager.addFileTransferListener(new FileTransferListener() {
    public void fileTransferRequest(FileTransferRequest request) {
            IncomingFileTransfer transfer = request.accept();
            try {
                InputStream input = transfer.recieveFile();
                //This will be a binary stream and you can process it. Create image and display it inline in your chat app.
            } catch (XMPPException e) {
                e.printStackTrace();
            }
        }
    }

这篇关于使用 Smack XMPP 发送内嵌图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆