asmack文件发送:transfer status = null

时间:2013-12-05 13:47:29

标签: android xmpp smack asmack

我正在使用asmack 18-0.8.9。 下面是我的发送文件方法

public void send()
{

    configureProviderManager(connection);

    FileTransferNegotiator.setServiceEnabled(connection, true);
    FileTransferManager manager = new FileTransferManager(connection);
    OutgoingFileTransfer transfer = manager.createOutgoingFileTransfer("xxxxx@jabber.ccc.de/Smack");

    File file = new File("/sdcard/DCIM/Camera/1385869353956.jpg");
    try {
        Log.d("file sending",file.getAbsolutePath()+" "+file.getName());
        configureProviderManager(connection);
       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))
                 System.out.println("refused  " + transfer.getError());
        else if( transfer.getStatus().equals(Status.error))
             System.out.println(" error " + transfer.getError());
        else if(transfer.getStatus().equals(Status.cancelled))
           System.out.println(" cancelled  " + transfer.getError());
        else
           System.out.println("Success");


    }

以下是我的接收器部分

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();
                    Log.d("receive","file name: "+transfer.getFileName());


                    File root = android.os.Environment.getExternalStorageDirectory();
                    File dir = new File (root.getAbsolutePath() + "/download");
                    dir.mkdirs();
                    File file = new File(dir+transfer.getFileName());
                        try {
                            transfer.recieveFile(file);
                        } catch (XMPPException e1) {
                            // TODO Auto-generated catch block

                        }
                        while(!transfer.isDone()) {
                           try{
                              Thread.sleep(1000L);
                           }catch (Exception e) {
                              Log.d("receive","thread sleep"+ e.getMessage());

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

                              Log.d("error","error status"+ transfer.getError() + "");
                           }
                           if(transfer.getException() != null) {

                              transfer.getException().printStackTrace();
                           }
                        }

                 };
               }.start();
            }
         });

我可以成功从其他桌面客户端接收文件,如psi,pidgin。当我尝试将文件从我的Android应用程序发送到其他桌面客户端或我自己的应用程序安装在其他手机上时,他们不会收到任何XMPP消息。当我从其他桌面客户端发送文件到我的Android应用程序时,我可以看到XMPP消息并成功接收消息。

下面是我的configureProviderManager方法

public void configureProviderManager() {


    ProviderManager.getInstance().addIQProvider("query","http://jabber.org/protocol/bytestreams", new BytestreamsProvider());
    ProviderManager.getInstance().addIQProvider("query","http://jabber.org/protocol/disco#items", new DiscoverItemsProvider());
    ProviderManager.getInstance().addIQProvider("query","http://jabber.org/protocol/disco#info", new DiscoverInfoProvider());

    }

0 个答案:

没有答案