powered by Jive Software

Smack API and transfering file

Hello !

I m actually coding an IM soft and I got a problem.

I can send file, but my receiving file listener doesn’t seems to work…

Can anybody help ?

This is my code :

Reception :

public void ReceiveFile() {

Log.e(“On entre en reception”,“RECEPTION”);

Thread thread = new Thread() {

public void run() {

ServiceDiscoveryManager sdm = ServiceDiscoveryManager

.getInstanceFor(m_connection);

if (sdm == null)

sdm = new ServiceDiscoveryManager(m_connection);

                      sdm.addFeature("[http://jabber.org/protocol/disco#info](http://jabber.org/protocol/disco#info)");

sdm.addFeature(“jabber:iq:privacy”);

// Create the file transfer manager

final FileTransferManager managerListner = new FileTransferManager(

m_connection);

FileTransferNegotiator

.setServiceEnabled(m_connection, true);

Log.e(“File transfere manager”, “created”);

// Create the listener

managerListner

.addFileTransferListener(new FileTransferListener() {

public void fileTransferRequest(

final FileTransferRequest request) {

Log.e(“Recieve File”,

“new file transfere request new file transfere request new file transfere request”);

Log.e(“file request”,

“from” + request.getRequestor());

IncomingFileTransfer transfer = request.accept();

Log.e(“Recieve File alert dialog”, “accepted”);

try {

transfer.recieveFile(new java.io.File("/sdcard/"+ request.getFileName()));

while (!transfer.isDone() || (transfer.getProgress() < 1)) {

Thread.sleep(1000);

Log.e(“Recieve File alert dialog”, "still receiving : "

  • (transfer.getProgress()) + " status "

  • transfer.getStatus());

if (transfer.getStatus().equals(Status.error)) {

// Log.i(“Error file”,

// transfer.getError().getMessage());

Log.e(“Recieve File alert dialog”,

"cancelling still receiving : "

  • (transfer.getProgress())

  • " status "

  • transfer.getStatus());

transfer.cancel();

break;

}

}

} catch (XMPPException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} catch (InterruptedException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}});

}

};

thread.start();

}

And this is my sending file code :

public void sendFile(final String receiver, final String directory) {

Thread thread = new Thread() {

public void run() {

ServiceDiscoveryManager sdm = ServiceDiscoveryManager.getInstanceFor(m_connection);

if (sdm == null)

{

sdm = new ServiceDiscoveryManager(m_connection);

}

            sdm.addFeature("[http://jabber.org/protocol/disco#info](http://jabber.org/protocol/disco#info)");

sdm.addFeature(“jabber:iq:privacy”);

FileTransferManager manager = new FileTransferManager(m_connection);

FileTransferNegotiator.setServiceEnabled(m_connection, true);

// Create the outgoing file transfer

OutgoingFileTransfer transfer = manager.createOutgoingFileTransfer(receiver+ “@pc-marvin” + “/Smack”);

Log.e(“transfere file”, “outgoingfiletransfere is created”);

try {

OutgoingFileTransfer.setResponseTimeout(30000);

transfer.sendFile(new File(directory), “Description”);

Log.e(“transfere file”, “sending file”);

while (!transfer.isDone()) {

try {

Thread.sleep(1000);

Log.e(“transfere file”, "sending file status "

  • transfer.getStatus() + "progress: "

  • transfer.getProgress());

if (transfer.getStatus() == Status.error) {

transfer.cancel();

break;

}

} catch (InterruptedException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}

} catch (XMPPException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

Log.e(“transfere file”, “sending file done”);

}

};

thread.start();

}

Where am I wrong ?