但打印状态始终保持打印: 日志:进度:0.0&状态:正在进行中
完成线程后 - 日志 ### Filetransfer无法完成。状态:正在进行中
如果我让这个线程运行删除计数它继续保持打印 - 进度: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();
}
}
}); `
感谢任何提示或帮助。
答案 0 :(得分:0)
我最近对asmack和smackx有一点经验,对他们来说不能太积极。
我不确切地知道你的问题来自哪里,但我可以告诉你这是正常的。在实际开始任何进度之前,您将首先得到一个进度加载= 0。 如果它是您发送的小文件,那么它只是发送得如此之快以至于没有任何真正的进展。
但是,如果你成功发送了一个更大的文件,这个功能确实很好用,会给你带来粗略的进展。
最后,我们得出的结论是,这个功能只是出错并限制并实现了我们自己的filetransfer xmpp消息,并通过我们自己的服务器处理它。像这样你也可以将文件发送给离线人员,成组(MUC)并显示双方都有不错的进展(发送和接收)。