1
我想在我使用SMACK和Openfire開發的Android聊天應用程序中實現文件傳輸功能。但是發送和接收文件時發生錯誤。因此任何人都可以幫助我解決此問題。感謝您提前。如何在android中使用SMACK創建發送和接收文件的偵聽器?
下面是接收文件的代碼。
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");
XMPPConnection.DEBUG_ENABLED = true;
// Create the file transfer manager
final FileTransferManager managerListner = new FileTransferManager(connection);
FileTransferNegotiator.setServiceEnabled(connection, true);
Log.i("File transfere manager", "created");
managerListner.addFileTransferListener(new FileTransferListener()
{
@Override
public void fileTransferRequest(FileTransferRequest request) {
// TODO Auto-generated method stub
Log.i("Recieve File","new file transfere request new file transfere request new file transfere request");
Log.i("file request","from" + request.getRequestor());
IncomingFileTransfer transfer = request.accept();
Log.i("Recieve File alert dialog", "accepted");
try {
transfer.recieveFile(new File("/mnt/sdcard/" + request.getFileName()));
while (!transfer.isDone() || (transfer.getProgress() < 1)) {
Thread.sleep(1000);
Log.i("Recieve File alert dialog", "still receiving : "+ (transfer.getProgress()) + " status "+ transfer.getStatus());
if (transfer.getStatus().equals(org.jivesoftware.smackx.filetransfer.FileTransfer.Status.error)) {
// Log.i("Error file",
// transfer.getError().getMessage());
Log.i("Recieve File alert dialog",
"cancelling still receiving : "
+ (transfer.getProgress())
+ " status "
+ transfer.getStatus());
transfer.cancel();
break;
}
}
}catch (XMPPException e) {
// TODO: handle exception
e.printStackTrace();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
這裏以下是我出現的錯誤。
02:48:58 PM RCV (1079277904): <iq type="error" id="6gQg0-6" to="admin-pc/cc4dd310" from="[email protected]/Smack"><si xmlns="http://jabber.org/protocol/si" id="jsi_3030055238839806007" profile="http://jabber.org/protocol/si/profile/file-transfer"><file xmlns="http://jabber.org/protocol/si/profile/file-transfer" name="sdcard"><desc>test</desc></file><feature xmlns="http://jabber.org/protocol/feature-neg"><x xmlns="jabber:x:data" type="form"><field var="stream-method" type="list-single"><option><value>http://jabber.org/protocol/bytestreams</value></option><option><value>http://jabber.org/protocol/ibb</value></option></field></x></feature></si><error code="405" type="cancel"><not-allowed xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"/></error></iq>
你能解釋一下xmpp.proxy.externalip是什麼?在我的情況下,我將http://192.168.0.102:9090設置爲externalip.Is可以嗎? – 2013-05-14 05:55:01
如果你的服務器是本地的,那麼192.168.0.102 如果它是在互聯網上的Web服務器上託管,那麼服務器的IP。用於映射您的域名的 。 但如果你在本地使用它,那麼你只需要192.168.0.102 希望它對你有幫助。 – Bug 2013-05-14 06:20:32
好的非常感謝你幫助我的錯誤。 – 2013-05-14 06:54:43