title: How to create listener for send and receive file using SMACK in android?
body: <p>I want to implement a file transfer functionality in my chat application which I have developed in Android using SMACK and Openfire.But I got an error in sending and receiving a file.So can anybody help me to solve this problem.Thanks In advance.</p>
  
  <p>Here following is a  code for receiving a file.</p>
  
  <pre><code>ServiceDiscoveryManager sdm = ServiceDiscoveryManager.getInstanceFor(connection);
          if (sdm == null)
              sdm = new ServiceDiscoveryManager(connection);
          sdm.addFeature("http://jabber.org/protocol/disco#info");
          sdm.addFeature("jabber:iq:privacy");
          XMPPConnection.DEBUG_ENABLED = true;
          // Create the file transfer manager
          final FileTransferManager managerListner = new FileTransferManager(connection);
          FileTransferNegotiator.setServiceEnabled(connection, true);
          Log.i("File transfere manager", "created");
          managerListner.addFileTransferListener(new FileTransferListener() 
          {
  
              @Override
              public void fileTransferRequest(FileTransferRequest request) {
                  // TODO Auto-generated method stub
                  Log.i("Recieve File","new file transfere request  new file transfere request   new file transfere request");
                  Log.i("file request","from" + request.getRequestor());
                  IncomingFileTransfer transfer = request.accept();
                  Log.i("Recieve File alert dialog", "accepted");
                  try {
                      transfer.recieveFile(new File("/mnt/sdcard/" + request.getFileName()));
                      while (!transfer.isDone() || (transfer.getProgress() &lt; 1)) {
  
                          Thread.sleep(1000);
                          Log.i("Recieve File alert dialog", "still receiving : "+ (transfer.getProgress()) + " status "+ transfer.getStatus());
                              if (transfer.getStatus().equals(org.jivesoftware.smackx.filetransfer.FileTransfer.Status.error)) {
                                  // Log.i("Error file",
                                  // transfer.getError().getMessage());
                                      Log.i("Recieve File alert dialog",
                                          "cancelling still receiving : "
                                                  + (transfer.getProgress())
                                                  + " status "
                                                  + transfer.getStatus());
                                      transfer.cancel();
                                      break;
                              }
                      }
                  }catch (XMPPException e) {
                      // TODO: handle exception
                          e.printStackTrace();
                  } catch (InterruptedException e) {
                      // TODO Auto-generated catch block
                          e.printStackTrace();
                  }
              }    
          });
  </code></pre>
  
  <p>Here following is an error Which I have arise.</p>
  
  <pre><code>02:48:58 PM RCV  (1079277904): &lt;iq type="error" id="6gQg0-6" to="admin-pc/cc4dd310" from="2222222222@admin-pc/Smack"&gt;&lt;si xmlns="http://jabber.org/protocol/si" id="jsi_3030055238839806007" profile="http://jabber.org/protocol/si/profile/file-transfer"&gt;&lt;file xmlns="http://jabber.org/protocol/si/profile/file-transfer" name="sdcard"&gt;&lt;desc&gt;test&lt;/desc&gt;&lt;/file&gt;&lt;feature xmlns="http://jabber.org/protocol/feature-neg"&gt;&lt;x xmlns="jabber:x:data" type="form"&gt;&lt;field var="stream-method" type="list-single"&gt;&lt;option&gt;&lt;value&gt;http://jabber.org/protocol/bytestreams&lt;/value&gt;&lt;/option&gt;&lt;option&gt;&lt;value&gt;http://jabber.org/protocol/ibb&lt;/value&gt;&lt;/option&gt;&lt;/field&gt;&lt;/x&gt;&lt;/feature&gt;&lt;/si&gt;&lt;error code="405" type="cancel"&gt;&lt;not-allowed xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"/&gt;&lt;/error&gt;&lt;/iq&gt;
  </code></pre>