开发者

XMPP SMACK file receiving not working on android

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(开发者_C百科);
            }
        }
    });

XMPP SMACK file receiving not working on android


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜