XMPP SMACK 文件接收在 Android 上不起作用

发布于 2024-12-05 15:40:45 字数 1837 浏览 1 评论 0原文

我无法接收从 SPARK 客户端传输的文件。 我正在使用 ASMACK jar 库,因此无法进入该库。

ServiceDiscoveryManager sdm = ServiceDiscoveryManager.getInstanceFor(connection);
    if (sdm == null){
        sdm = new ServiceDiscoveryManager(connection);
    sdm.addFeature("http://jabber.org/protocol/disco#info");
    sdm.addFeature("jabber:iq:privacy");
    } 

//  new ServiceDiscoveryManager(connection);
    FileTransferNegotiator.setServiceEnabled(connection, false);
    FileTransferManager manager = new FileTransferManager(connection);
    manager.addFileTransferListener(new FileTransferListener() {
        public void fileTransferRequest(FileTransferRequest request) {
            Log.d("", "allows file...");
            if (request != null) {
                // Accept it
                IncomingFileTransfer transfer = request.accept();
                try {

                   // String pathsd =    Environment.getExternalStorageDirectory().toString();

                    String path = "/sdcard/"+ request.getFileName();
                    transfer.recieveFile(new File(path));

                    // transfer.recieveFile(new
                    // File(request.getFileName()));
                     System.out.println("File " + request.getFileName() + "Received Successfully");
    //                      Log.d("", "rece: " +    request.getFileName());                     
    //                      Log.d("", "path: " + request.getFileName());
                    // InputStream input = transfer.recieveFile();
                } catch (XMPPException ex) {
                    Log.d("", "er: " + ex);
                }
               } else {
                Log.d("", "reject file...");
                request.reject();
            }
        }
    });

在此处输入图像描述

I am unable to recive the file, which I am transfering from SPARK client.
I am using ASMACK jar Library so it's not possible to get into the library.

ServiceDiscoveryManager sdm = ServiceDiscoveryManager.getInstanceFor(connection);
    if (sdm == null){
        sdm = new ServiceDiscoveryManager(connection);
    sdm.addFeature("http://jabber.org/protocol/disco#info");
    sdm.addFeature("jabber:iq:privacy");
    } 

//  new ServiceDiscoveryManager(connection);
    FileTransferNegotiator.setServiceEnabled(connection, false);
    FileTransferManager manager = new FileTransferManager(connection);
    manager.addFileTransferListener(new FileTransferListener() {
        public void fileTransferRequest(FileTransferRequest request) {
            Log.d("", "allows file...");
            if (request != null) {
                // Accept it
                IncomingFileTransfer transfer = request.accept();
                try {

                   // String pathsd =    Environment.getExternalStorageDirectory().toString();

                    String path = "/sdcard/"+ request.getFileName();
                    transfer.recieveFile(new File(path));

                    // transfer.recieveFile(new
                    // File(request.getFileName()));
                     System.out.println("File " + request.getFileName() + "Received Successfully");
    //                      Log.d("", "rece: " +    request.getFileName());                     
    //                      Log.d("", "path: " + request.getFileName());
                    // InputStream input = transfer.recieveFile();
                } catch (XMPPException ex) {
                    Log.d("", "er: " + ex);
                }
               } else {
                Log.d("", "reject file...");
                request.reject();
            }
        }
    });

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

你好,陌生人 2024-12-12 15:40:45

不知道您的 asmack 基于哪个版本的 Smack,但文件传输存在已知问题 in Smack,asmack 和 Spark 都是基于它的。

Don't know what version of Smack your asmack is based on, but there is a known issue with file transfer in Smack, which both asmack and Spark are based on.

痕至 2024-12-12 15:40:45

Beems asmack 构建过程有详细记录 并且来源对所有人开放。

您的代码看起来是正确的,但为什么将其设置

FileTransferNegotiator.setServiceEnabled(connection, false);

为 false?

XMPP 中的文件传输是一个相当复杂的主题。有多种方法(至少 4 种)可以将文件从一种资源获取到另一种资源。由于您没有提供更多详细信息,我只能为您提供有关如何调试此问题的一般设备:

在 smack 中启用连接调试,这将打印并记录所有进出的 XMPP 数据包。与文件传输相关的 XMPP 节,并确保它们按照 XEP 中指定的方式运行。这可能会提示出什么问题。

Beems asmack build process is well documented and also the sources are open for everyone.

Your code looks right, but why do you set this

FileTransferNegotiator.setServiceEnabled(connection, false);

to false?

File transfer in XMPP is a rather complex topic. There are various methods (at least 4), to get a file from one resource to another. As you provided no further details I can only give you general device on how to debug this:

Enable connection debug in smack, which will print out and log all XMPP packets that go in and out. Trace the XMPP stanzas that relate to the file transfer and make sure they behave as specified in the XEPs. This may provides a hint about whats going wrong.

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