4

I am working on chatting application and i have to implement file transfer using smack api. I am able to Connect to the open fire server and can also chat with another client.But i dont know how to implement file transfer..I have found a code snippet but i am not ableto send it using that also.Following is the code snippet i am using:

public void SendFile(final String Receiver, final String Directory) {
        Thread thread = new Thread() {
            public void run() {
            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");
            // Create the file transfer manager
            FileTransferManager manager = new FileTransferManager(
                    connection);
            FileTransferNegotiator
            .setServiceEnabled(connection, true);

            // Create the outgoing file transfer
            OutgoingFileTransfer transfer = manager
            .createOutgoingFileTransfer("alok@chd-akumar4" );
            Log.i("transfere file", "outgoingfiletransfere is created");
            try {
                OutgoingFileTransfer.setResponseTimeout(30000);
                transfer.sendFile(new File(Directory), "Description");
                Log.i("transfere file", "sending file");
                while (!transfer.isDone()) {
                    try {
                        Thread.sleep(1000);
                        Log.i("transfere file", "sending file status "
                                + transfer.getStatus() + "progress: "
                                + transfer.getProgress());
                        if (transfer.getStatus() == org.jivesoftware.smackx.filetransfer.FileTransfer.Status.error) {
                            transfer.cancel();
                            Log.e("","EEEEEERRRRRRRROOORRRRR");
                            break;
                        }
                    } catch (InterruptedException e) {
                        // TODO Auto-generated catch block
                        Log.e("aaaaaaaaaaaaaaa","aaaa"+e);
                        e.printStackTrace();
                    }
                }
            } 
            catch (XMPPException e) {
                // TODO Auto-generated catch block
                Log.e("aaaaaaaaaaaaaaa","aaaa"+e);
                e.printStackTrace();
            }
            Log.i("transfere file", "sending file done");
        }
        };
        thread.start();
    }

can any one help me finding the solution..

Karan_Rana
  • 2,813
  • 2
  • 26
  • 35

2 Answers2

0

Now we have 4.1.0 with updated API's.

FileTransferRequest and StreamInitiation makes it more easy now.

Please check with latest Smack version.

https://www.igniterealtime.org/builds/smack/docs/4.1.0/documentation/extensions/filetransfer.html

Flow
  • 23,572
  • 15
  • 99
  • 156
Narasimha
  • 759
  • 6
  • 8
  • flow i am having issues with that API, could you help me please? [link](http://stackoverflow.com/questions/31107005/android-smack-4-1-1-file-transfering-error-could-not-establish-socket) – kobbycoder Jun 29 '15 at 14:06
0

If you are using version 3.2.x, there is a known problem with file transfer. Try using 3.1 to see if it fixes your problem.

Robin
  • 24,062
  • 5
  • 49
  • 58