问题
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("919974740823@127.0.0.1/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
回答1:
I have also having same issue but after adding this line
SmackConfiguration.setDefaultPacketReplyTimeout(15000);
Its working fine.
来源:https://stackoverflow.com/questions/11666963/file-is-not-being-transferred-in-smack-api