Problemas con la API de Smack

I am using following code for file transfer in android application using Smack Api and Oepnfire Server. I am not getting any error but problem is that when I send file , I get Cancelled Status at 198 line. Can anybody help me? .Thanks in advance .

            String to = mRecipient.getText().toString();
            String text = mSendText.getText().toString();
            // Uri uri = Uri.fromFile(new
            // File("file:///android_asset/test.txt"));
            if (new File("/data/data/" + getPackageName() + "/"
                    + "test.txt").exists()) {
                Log.d("XMPPClient File Exist", "exist");

            }
            SmackConfiguration.setPacketReplyTimeout(15000);
            ConnectionConfiguration config = new ConnectionConfiguration(
                    "192.168.1.200", 5222);
            // config.setRosterLoadedAtLogin(true);
            // config.setSendPresence(true);
            // config.setSASLAuthenticationEnabled(false);
            config.setReconnectionAllowed(true);
            connection = new XMPPConnection(config);
            /*
             * ConnectionConfiguration connConfig = new
             * ConnectionConfiguration("192.168.1.200", 5222, "");
             * connConfig.setReconnectionAllowed(true);;
             * 
             * connection = new XMPPConnection(connConfig);
             */
            try {
                connection.connect();
            } catch (XMPPException e2) {
                // TODO Auto-generated catch block
                e2.printStackTrace();
            }

            try {
                connection.connect();
            } catch (XMPPException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }
            // connection.login(userName, password);

            ServiceDiscoveryManager servicemanager = ServiceDiscoveryManager
                    .getInstanceFor(connection);
            if (servicemanager == null)
                servicemanager = new ServiceDiscoveryManager(connection);
            servicemanager
                    .addFeature("http://jabber.org/protocol/disco#info");
            servicemanager.addFeature("jabber:iq:privacy");

            // Log.d("XMPPClient Txt File", uri.toString());
            try {
                // Create the outgoing file transfer
                manager = new FileTransferManager(connection);
                FileTransferNegotiator.setServiceEnabled(connection, true);
                OutgoingFileTransfer transfer = manager
                        .createOutgoingFileTransfer("test@192.168.1.200/Smack");
                // Send the file

                // getBaseContext().getAssets().open("Entity");
                // OutgoingFileTransfer.setResponseTimeout(30000);
                transfer.sendFile(new File("/data/data/" + getPackageName()
                        + "/" + "test.txt"), "You won't believe this!");

                while (!transfer.isDone()) {
                    try {
                        Thread.sleep(1000);
                        Log.i("transfere file", "sending file status "
                                + transfer.getStatus() + "progress: "
                                + transfer.getProgress());
                        if (transfer.getStatus() == org.jivesoftware.smackx.filetransfer.FileTransfer.Status.error) {
                            transfer.cancel();
                            Log.e("", transfer.getStatus().toString());
                            Log.e("", "EEEEEERRRRRRRROOORRRRR");
                            break;
                        }
                    } catch (InterruptedException e) {
                        // TODO Auto-generated catch block
                        Log.e("aaaaaaaaaaaaaaa", "aaaa" + e);
                        e.printStackTrace();
                    }
                }

            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

preguntado el 31 de enero de 12 a las 08:01

1 Respuestas

Yes, you have to setup FileTransferListener and accept the file

public class MyFileTransferListener implements FileTransferListener {

@Override
public void fileTransferRequest(final FileTransferRequest request) {
 Boolean result = false;
    IncomingFileTransfer ift = request.accept();

this is an example code, after accepting get the file.. also dont forget to start the listener when connecting to xmpp server

respondido 30 nov., 16:18

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.