AnsweredAssumed Answered

File Transfer doesn't support .Doc x, .PDF , . ZIP type files  in asmack android

Question asked by pooja on Mar 4, 2016

      I am using asmack-android-19-0.8.10.jar library in my chat application for file transfer and chat, I'm able to transfer Image,video,audio type file but issue in transfer .Doc x, .PDF , . ZIP type doccument files.How to solve this issue?

 

The code for file send:

 

FileTransferManager manager = new FileTransferManager(connection);

OutgoingFileTransfer transfer = manager.createOutgoingFileTransfer('usre2@myHost/Smack');

File file = new File(filenameWithPath);

try {

   transfer.sendFile(file, 'test_file');

}

catch (XMPPException e) {

   e.printStackTrace();

}

 

 

while(!transfer.isDone()) {

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

      System.out.println('ERROR!!! ' + transfer.getError());

   } else if (transfer.getStatus().equals(Status.cancelled)

                    || transfer.getStatus().equals(Status.refused)) {

      System.out.println('Cancelled!!! ' + transfer.getError());

   }

 

   try {

      Thread.sleep(1000L);

  } catch (InterruptedException e) {

     e.printStackTrace();

  }

}

 

if(transfer.getStatus().equals(Status.refused) || transfer.getStatus().equals(Status.error)

|| transfer.getStatus().equals(Status.cancelled)){

   System.out.println('refused cancelled error ' + transfer.getError());

} else {

   System.out.println('Success');

}

 

And the code for file receive:

 

FileTransferManager manager = new FileTransferManager(connection);

 

manager.addFileTransferListener(new FileTransferListener() {

public void fileTransferRequest(final FileTransferRequest request) {

      new Thread(){

         @Override

         public void run() {

            IncomingFileTransfer transfer = request.accept();

            File mf = Environment.getExternalStorageDirectory();

            File file = new File(mf.getAbsoluteFile()+'/DCIM/Camera/' + transfer.getFileName());

            try{

                transfer.recieveFile(file);

                while(!transfer.isDone()) {

                   try{

                      Thread.sleep(1000L);

                   }catch (Exception e) {

                      Log.e('', e.getMessage());

                   }

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

                      Log.e('ERROR!!! ', transfer.getError() + '');

                   }

                   if(transfer.getException() != null) {

                      transfer.getException().printStackTrace();

                   }

                }

             }catch (Exception e) {

                Log.e('', e.getMessage());

            }

         };

       }.start();

    }

});

Outcomes