I use Smack and xmpp to send messages in the application, the question arose how to get the file in the application correctly.

I use this file transfer listener to get the files in the application:

 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("Error", e.getMessage()); } if (transfer.getStatus().equals(FileTransfer.Status.error)) { Log.e("ERROR!!! ", transfer.getError() + ""); } if (transfer.getException() != null) { transfer.getException().printStackTrace(); } } Log.e("", e.getMessage()); } } }.start(); } 

});

I use the OpenFire server, and I also downloaded the Psi client for sending messages and testing. When I try to send a Psi file to a user who has an Android application installed on the phone, Psi requests the request before sending the file, и когда я проверяю в дебаггере, то программа не заходит в строчку кода IncomingFileTransfer transfer = request.accept (); How to accept this request on the phone programmatically? What's wrong?

enter image description here

    2 answers 2

    Found solutions, in order to accept the file on another device you need to use FileTransferListener, example code:

      public class FileTransferIMPL implements FileTransferListener { @Override public void fileTransferRequest(final FileTransferRequest request) { final IncomingFileTransfer transfer = request.accept(); try { InputStream is = transfer.recieveFile(); } catch (IOException e) { e.printStackTrace(); } } catch (XMPPException ex) { Logger.getLogger(MyXMPP.class.getName()).log(Level.SEVERE, null, ex); } catch (SmackException e) { e.printStackTrace(); } } } 

      When getting connection, set

       Roster.setDefaultSubscriptionMode(Roster.SubscriptionMode.accept_all); 
      • I tried, but the file is still not transmitted. - Lucky_girl