File is not being transferred in smack API
Asked Answered
H

1

1

I am developing a chat application in which i need to give support of file transfer. For this i am using Smack API. But my file is not being transferred and i am getting the File status Error and progress 0.0
i have googled on net but they all are used the same way to send the file. but i am getting the error.
I know there is a couple of question regarding this issue but proper solution is not given.

so is there anyone who have idea about this? How to solve this problem?

Edit:

I have try with change the 127.0.0.1 to 10.0.2.2, and now i got the status is Negotiating but after some tries i got the status Error.

Here is my code for file transfer:

ServiceDiscoveryManager sdm = ServiceDiscoveryManager
                        .getInstanceFor(connection);
                if (sdm == null)
                    sdm = new ServiceDiscoveryManager(connection);
                sdm.addFeature("http://jabber.org/protocol/disco#info");
                sdm.addFeature("http://jabber.org/protocol/disco#item");
                sdm.addFeature("jabber:iq:privacy");
                Log.i("send file", "send file");
                FileTransferManager manager = new FileTransferManager(
                        connection);
                FileTransferNegotiator.setServiceEnabled(
                        connection, true);
                OutgoingFileTransfer transfer = manager
                        .createOutgoingFileTransfer("[email protected]/Smack");
                Log.i("transfer file",
                        "outgoingfiletransfer is created");
                try {
                    OutgoingFileTransfer.setResponseTimeout(30000);
                    transfer.sendFile(
                            new File(path_file+"/"+"andr.jpeg"),
                            "Description");
                    Log.i("transfer file", "sending file");

                    Log.i("transfer file","the path is :"+path_file+"/"+"andr.jpeg");
                    while (!transfer.isDone()) {
                        try {
                            Thread.sleep(1000);
                            Log.i("transfer file",
                                    "sending file status :- "
                                            + transfer.getStatus()
                                            + " "
                                            + "progress:-"
                                            + transfer
                                                    .getProgress());
                            if (transfer.getStatus() == org.jivesoftware.smackx.filetransfer.FileTransfer.Status.error) {
                                transfer.cancel();
                                Log.e("", "ERROR");
                                break;
                            }
                        } catch (InterruptedException e) {
                            // TODO Auto-generated catch block
                            Log.e("catch", "catch" + e);
                            e.printStackTrace();
                        }
                    }
                } catch (XMPPException e) {
                    // TODO Auto-generated catch block
                    Log.e("catch", "catch" + e);
                    e.printStackTrace();
                }
                Log.i("transfer file", "--------");
            }

Any help and suggestion will be appreciated.

Thanks

Henke answered 26/7, 2012 at 10:2 Comment(10)
nope still searching the solution,if you get any solution then please let me know ThanksHenke
I am trying to receive a file and getting similar problems. Any idea how to do that?Farrar
@juned Did you find out the solution? If you can send file via asmack, can you show me how? Thank you very much!!Yaupon
Yeah sure i will let you know if it worksHenke
i got this error with that code see thisHenke
@Yul that code not worked for me even on emulator. can you help me please ?Henke
Hi, Did you check this link. It is working. harryjoy.com/2012/08/18/…Unconformity
yeah,you check my comments on that links. did it worked for you @JKRC ?Henke
no I did not check your comments.Unconformity
ohh i see, actually i tried with that code but not succeeded,if its worked for you then please share your idea .@JKRCHenke
M
0

I have also having same issue but after adding this line

SmackConfiguration.setDefaultPacketReplyTimeout(15000);

Its working fine.

Masefield answered 28/7, 2016 at 13:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.