我正在使用xmpp進行文件傳輸。這是我的文件傳輸代碼。使用xmpp在Android中傳輸文件
ServiceDiscoveryManager sdm = ServiceDiscoveryManager.getInstanceFor(connection);
if (sdm == null)
sdm = new ServiceDiscoveryManager(connection);
FileTransferManager manager = new FileTransferManager(connection);
OutgoingFileTransfer transfer = manager.createOutgoingFileTransfer("[email protected]/Smack");
File file = new File(filenameWithPath);
try {
transfer.sendFile(file, "You won't believe this!");
} catch (XMPPException e) {
e.printStackTrace();
}
while (!transfer.isDone()) {
Log.i("progres", "" + transfer.getProgress());
}
if (transfer.getStatus().equals(Status.refused)|| transfer.getStatus().equals(Status.error) || transfer.getStatus().equals(Status.cancelled))
{
System.out.println("refused cancelled error " + transfer.getError());
} else
{
System.out.println("Success");
}
問題是,當接受文件的時候它會崩潰。
日誌文件:
FATAL EXCEPTION: File Transfer jsi_1117022495316866568
java.lang.ClassCastException: org.jivesoftware.smack.util.PacketParserUtils$2
at org.jivesoftware.smackx.filetransfer.FileTransferNegotiator.negotiateOutgoingTransfer(FileTransferNegotiator.java:401)
at org.jivesoftware.smackx.filetransfer.OutgoingFileTransfer.negotiateStream(OutgoingFileTransfer.java:359)
at org.jivesoftware.smackx.filetransfer.OutgoingFileTransfer.access$100(OutgoingFileTransfer.java:35)
at org.jivesoftware.smackx.filetransfer.OutgoingFileTransfer$2.run(OutgoingFileTransfer.java:214)
at java.lang.Thread.run(Thread.java:1019)
請檢查此鏈接:http://stackoverflow.com/questions/13119371/用-asmack-or-any-alternatives發送文件,並下載這個文件asmack-jse-buddycloud-2010.12.11.jar並以這種方式實施。 –