我正在開發一個聊天應用程序,我需要在對等聊天用戶之間發送圖像。現在我能夠發送圖像,我的文件接收器也接受請求並開始接收文件。Android aSmack XMPP文件傳輸總是顯示進行中和狀態0
但打印狀態始終保持印刷: LOG:進展:0.0 &況:正在
和精加工線後 - LOG ###文件傳輸不完整。現況:正在
如果我讓這個線程運行刪除指望它continuesly保持印刷 - 進展:0.0 &況:正在
有時全圖像後收到..這需要很長的時間,很多次的一半或大小爲0.
private ServiceDiscoveryManager sdm;
if (sdm == null)
sdm = new ServiceDiscoveryManager(connection);
Log.v("---fileReceive----","after discover connectin.....");
sdm.addFeature("http://jabber.org/protocol/disco#info");
sdm.addFeature("jabber:iq:privacy");
ProviderManager.getInstance().addIQProvider("query","http://jabber.org/protocol/bytestreams", new BytestreamsProvider());
ProviderManager.getInstance().addIQProvider("query","http://jabber.org/protocol/disco#items", new DiscoverItemsProvider());
ProviderManager.getInstance().addIQProvider("query","http://jabber.org/protocol/disco#info", new DiscoverInfoProvider());
ProviderManager.getInstance().addIQProvider("si", "http://jabber.org/protocol/si", new StreamInitiationProvider());
ProviderManager.getInstance().addIQProvider("query", "http://jabber.org/protocol/bytestreams", new BytestreamsProvider());
ProviderManager.getInstance().addIQProvider("open", "http://jabber.org/protocol/ibb", new OpenIQProvider());
ProviderManager.getInstance().addIQProvider("data", "http://jabber.org/protocol/ibb", new DataPacketProvider());
ProviderManager.getInstance().addIQProvider("close", "http://jabber.org/protocol/ibb", new CloseIQProvider());
ProviderManager.getInstance().addExtensionProvider("data", "http://jabber.org/protocol/ibb", new DataPacketProvider());
sdm = ServiceDiscoveryManager.getInstanceFor(connection);
FileTransferNegotiator.setServiceEnabled(connection, true);
FileTransferNegotiator.IBB_ONLY = true;
manager = new FileTransferManager(connection);
// Create the listener
// fListner=new FileTransferListener() {
manager.addFileTransferListener(new FileTransferListener() {
@Override
public void fileTransferRequest(FileTransferRequest request) {
// TODO Auto-generated method stub
Log.v("----Recieve File",
"new file transfere requesttttt------------");
Log.v("-----file request","from" + request.getRequestor());
// Accept it
try {
IncomingFileTransfer transfer = request.accept();
Log.v("----transfer--","accepted");
double percents = 0.0;
int currentCycle = 0;
transfer.recieveFile(new File(Environment.getExternalStorageDirectory().getPath()+"/"+transfer.getFileName()));
while(!transfer.isDone() && currentCycle < 100) {
if(transfer.getStatus().equals(Status.in_progress)) {
percents = ((int) (transfer.getProgress()*10000))/100.0;
//percents is 100.0 after 1 cycle
Log.i(LOG, "Filetransfer Progress: "+percents + " Status: "+transfer.getStatus().toString());
} else if (transfer.getStatus().equals(Status.error)) {
Log.e(LOG, "FileTransfer ERROR"+transfer.getError().getMessage());
break;
}
currentCycle ++;
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
if(transfer.getStatus().equals(Status.complete)) {
if (onFileReceivedListener != null) {
onFileReceivedListener.onFileReceived(transfer);
}
}else{
Log.e(LOG, "###Filetransfer not complete. Status:" + transfer.getStatus().toString());
//FILE IS HERE
}
} catch (XMPPException e) {
e.printStackTrace();
}
}
}); `
任何提示或幫助表示讚賞。
你使用什麼聊天服務器? – 2013-03-14 13:03:53
這不是一個真正的答案,而是一個很好的起點:https://github.com/Flowdalic/asmack/wiki/aSmack-XMPP-File-Transfer – Flow 2013-03-15 20:01:45
@Vyoma你有沒有完成這項任務? – 2015-01-30 07:49:39