我正在开发一个聊天应用程序,我需要在其中在点对点聊天用户之间发送图像。现在我能够发送图像并且我的文件接收器也接受请求并开始接收文件。
但打印状态始终保持打印: LOG: Progress:0.0 & Status:In Progress
并在完成线程后 - LOG ###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();
}
}
}); `
任何提示或帮助表示赞赏。