Hello folks,
I was able now to use file transfer and it works without problems. But now, what happens if the receiver is offline? I can´t find any hint here or in SO. In that way, I can receive files with the FileTransferListener. But if I am sending a file to offline receiver, after going online, the receiver gets no file (like for example it is possible with simple message).
mFileTransferManager = FileTransferManager.getInstanceFor(mConnection);
mFileTransferManager.addFileTransferListener(new FileTransferListener() {
@Override
public void fileTransferRequest(FileTransferRequest request) {
IncomingFileTransfer incomingFileTransfer = request.accept();
String fileName = incomingFileTransfer.getFileName();
String senderJid = incomingFileTransfer.getPeer();
try {
InputStream inputStream = incomingFileTransfer.recieveFile();
ByteArrayOutputStream bao = new ByteArrayOutputStream();
int read;
byte[] buf = new byte[1024];
while ((read = inputStream.read(buf, 0, buf.length)) != -1) {
bao.write(buf, 0, read);
}
bao.flush();
byte[] dataReceived = bao.toByteArray();
saveFile(senderJid, fileName, dataReceived);
} catch (SmackException e) {
e.printStackTrace();
} catch (XMPPException.XMPPErrorException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
});
Has anybody some experience about that? I haven´t found the right doc in the smack API.