AndroidでSmackライブラリとopen-fireサーバーを使用してファイルを転送しているときに問題が発生し、あるデバイスから別のデバイスにファイルを転送しているときに空のファイルが他のデバイスで受信され、0KBのサイズが表示されます。開いたときに空白の画面が表示されます。その背後にある問題を知っています。
このリンクを実装に使用しています。私のコードは次のとおりです。
public void ReceiveFile() {
ServiceDiscoveryManager sdm = ServiceDiscoveryManager.getInstanceFor(connection);
if (sdm == null)``
{
sdm = new ServiceDiscoveryManager(connection);
Log.e("service discovery", "SDM");
sdm.addFeature("http://jabber.org/protocol/disco#info");
sdm.addFeature("jabber:iq:privacy");
}
FileTransferManager manager = new FileTransferManager(connection);
Log.e("after manager", "manager");
manager.addFileTransferListener(new FileTransferListener() {
public void fileTransferRequest(final FileTransferRequest request) {
new Thread(){
@Override
public void run() {
Log.e("Thread running", "starting");
IncomingFileTransfer transfer = request.accept();
File mf = Environment.getExternalStorageDirectory();
Log.e("path", mf.getAbsoluteFile()+"/DCIM/" + transfer.getFileName());
File file = new File(mf.getAbsoluteFile()+"/DCIM/" + transfer.getFileName());
try{
transfer.recieveFile(file);
while(!transfer.isDone()) {
try{
Thread.sleep(1000L);
}catch (Exception e) {
Log.e("", e.getMessage());
}
if(transfer.getStatus().equals(org.jivesoftware.smackx.filetransfer.FileTransfer.Status.error)) {
Log.e("ERROR!!! ", transfer.getError() + "");
}
if(transfer.getException() != null) {
transfer.getException().printStackTrace();
Log.e("not null", "print stack success");
}
}
}catch (Exception e) {
Log.e("", e.getMessage());
}
};
}.start();
}
});
}
public void sndFile(final String path, final String receiver) {
ServiceDiscoveryManager sdm = ServiceDiscoveryManager.getInstanceFor(connection);
if (sdm == null)
{
sdm = new ServiceDiscoveryManager(connection);
Log.e("service discovery", "SDM");
sdm.addFeature("http://jabber.org/protocol/disco#info");
sdm.addFeature("jabber:iq:privacy");
}
FileTransferManager manager = new FileTransferManager(connection);
OutgoingFileTransfer transfer = manager.createOutgoingFileTransfer(receiver+"/Smack");
File file = new File(path);
try {
transfer.sendFile(file, "test_file");
} catch (XMPPException e) {
e.printStackTrace();
}
while(!transfer.isDone()) {
if(transfer.getStatus().equals(org.jivesoftware.smackx.filetransfer.FileTransfer.Status.error)) {
System.out.println("ERROR!!! " + transfer.getError());
Log.e("while status error", "error");
} else if (transfer.getStatus().equals(org.jivesoftware.smackx.filetransfer.FileTransfer.Status.refused)
|| transfer.getStatus().equals(org.jivesoftware.smackx.filetransfer.FileTransfer.Status.cancelled)) {
System.out.println("Cancelled!!! " + transfer.getError());
Log.e("while Cancelled", "cancel refuse");
}
try {
Thread.sleep(1000L);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
if(transfer.getStatus().equals(org.jivesoftware.smackx.filetransfer.FileTransfer.Status.refused) || transfer.getStatus().equals(org.jivesoftware.smackx.filetransfer.FileTransfer.Status.error)
|| transfer.getStatus().equals(org.jivesoftware.smackx.filetransfer.FileTransfer.Status.cancelled)){
System.out.println("refused cancelled error " + transfer.getError());
Log.e("if cancelled", "refused cancel");
} else {
System.out.println("Success");
Log.e("if no error", "Success");
j=0;
arrList_messages.add("File "+transfer.getFileName()+"Sent");
arrList_messages.add(" ");
setListAdapter();
setListAdapterGreen();
}
}
My LogCat 送信中:
07-12 12:45:47.330: W/IInputConnectionWrapper(22548): showStatusIcon on inactive InputConnection
07-12 12:45:57.511: I/Path:(22548): /mnt/sdcard/Pictures/Screenshots/Screenshot_2013-07-08-13-08-57.png
07-12 12:45:57.514: I/Started(22548): Applicationtrue
07-12 12:45:57.515: I/Resumed(22548): Applicationtrue
07-12 12:45:59.560: W/System.err(22548): java.lang.InterruptedException
07-12 12:45:59.561: W/System.err(22548): at java.util.concurrent.locks.AbstractQueuedSynchronizer.acquireInterruptibly(AbstractQueuedSynchronizer.java:1198)
07-12 12:45:59.561: W/System.err(22548): at java.util.concurrent.locks.ReentrantLock.lockInterruptibly(ReentrantLock.java:311)
07-12 12:45:59.561: W/System.err(22548): at java.util.concurrent.ArrayBlockingQueue.put(ArrayBlockingQueue.java:292)
07-12 12:45:59.561: W/System.err(22548): at org.jivesoftware.smack.PacketWriter.sendPacket(PacketWriter.java:97)
07-12 12:45:59.561: W/System.err(22548): at org.jivesoftware.smack.XMPPConnection.sendPacket(XMPPConnection.java:488)
07-12 12:45:59.561: W/System.err(22548): at org.jivesoftware.smackx.filetransfer.Socks5TransferNegotiator.negotiateIncomingStream(Socks5TransferNegotiator.java:130)
07-12 12:45:59.562: W/System.err(22548): at org.jivesoftware.smackx.filetransfer.FaultTolerantNegotiator$NegotiatorService.call(FaultTolerantNegotiator.java:181)
07-12 12:45:59.562: W/System.err(22548): at org.jivesoftware.smackx.filetransfer.FaultTolerantNegotiator$NegotiatorService.call(FaultTolerantNegotiator.java:166)
07-12 12:45:59.562: W/System.err(22548): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
07-12 12:45:59.562: W/System.err(22548): at java.util.concurrent.FutureTask.run(FutureTask.java:137)
07-12 12:45:59.562: W/System.err(22548): at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:442)
07-12 12:45:59.562: W/System.err(22548): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
07-12 12:45:59.562: W/System.err(22548): at java.util.concurrent.FutureTask.run(FutureTask.java:137)
07-12 12:45:59.562: W/System.err(22548): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
07-12 12:45:59.562: W/System.err(22548): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
07-12 12:45:59.562: W/System.err(22548): at java.lang.Thread.run(Thread.java:856)
受信中の LogCat:
06-19 11:22:41.912: W/System.err(15386): java.util.concurrent.ExecutionException:
06-19 11:22:41.912: W/System.err(15386): -- caused by: No response from remote client:
06-19 11:22:41.913: W/System.err(15386): at java.util.concurrent.FutureTask$Sync.innerGet(FutureTask.java:233)
06-19 11:22:41.913: W/System.err(15386): at java.util.concurrent.FutureTask.get(FutureTask.java:90)
06-19 11:22:41.913: W/System.err(15386): at org.jivesoftware.smackx.filetransfer.IncomingFileTransfer.negotiateStream(IncomingFileTransfer.java:193)
06-19 11:22:41.913: W/System.err(15386): at org.jivesoftware.smackx.filetransfer.IncomingFileTransfer.access$100(IncomingFileTransfer.java:47)
06-19 11:22:41.913: W/System.err(15386): at org.jivesoftware.smackx.filetransfer.IncomingFileTransfer$1.run(IncomingFileTransfer.java:124)
06-19 11:22:41.913: W/System.err(15386): at java.lang.Thread.run(Thread.java:856)
06-19 11:22:41.913: W/System.err(15386): -- caused by: No response from remote client:
06-19 11:22:41.914: W/System.err(15386): at org.jivesoftware.smackx.filetransfer.FaultTolerantNegotiator.createIncomingStream(FaultTolerantNegotiator.java:113)
06-19 11:22:41.914: W/System.err(15386): at org.jivesoftware.smackx.filetransfer.IncomingFileTransfer$2.call(IncomingFileTransfer.java:186)
06-19 11:22:41.914: W/System.err(15386): at org.jivesoftware.smackx.filetransfer.IncomingFileTransfer$2.call(IncomingFileTransfer.java:183)
06-19 11:22:41.914: W/System.err(15386): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
06-19 11:22:41.914: W/System.err(15386): at java.util.concurrent.FutureTask.run(FutureTask.java:137)
06-19 11:22:41.914: W/System.err(15386): at org.jivesoftware.smackx.filetransfer.IncomingFileTransfer.negotiateStream(IncomingFileTransfer.java:190)
06-19 11:22:41.914: W/System.err(15386): ... 3 more
06-19 11:22:41.914: E/not null(15386): print stack success
06-19 11:22:41.914: E/ERROR!!!(15386): null