2013-05-11 30 views
1

如何在Android中使用Smack與Openserver接收傳輸文件?以下是我用來接收文件的代碼。但出現錯誤,無法錄製任何文件。如何在Android中的Smack中接收文件?

ServiceDiscoveryManager sdm = ServiceDiscoveryManager.getInstanceFor(connection); 
     if(sdm == null) 
     { 
      sdm = new ServiceDiscoveryManager(connection); 
      sdm.addFeature("http://jabber.org/protocol/disco#info"); 
      sdm.addFeature("http://jabber.org/protocol/disco#item"); 
      sdm.addFeature("jabber:iq:privacy"); 
      XMPPConnection.DEBUG_ENABLED = true; 
     } 

     FileTransferManager manager=new FileTransferManager(connection); 
     FileTransferNegotiator.setServiceEnabled(connection, true); 
     manager.addFileTransferListener(new FileTransferListener() 
     {  
      @Override 
      public void fileTransferRequest(final FileTransferRequest request) 
      { 
      Log.i("Recieve File","new file transfere request new file transfere request new file transfere request"); 
      Log.i("file request","from" + request.getRequestor()); 
      // TODO Auto-generated method stub 
      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 
        { 
         System.out.println("<====== Receives ======>"); 
         transfer.recieveFile(file); 
         while (!transfer.isDone()|| (transfer.getProgress() < 1)) { 
          Thread.sleep(1000); 
          Log.i("Recieve File alert dialog","still receiving : "+ (transfer.getProgress()) + " status " + transfer.getStatus()); 
          if (transfer.getStatus().equals("error")) { 
            Log.i("Recieve File alert dialog", "cancelling still receiving : "+ (transfer.getProgress())+ " status "+ transfer.getStatus()); 
            transfer.cancel(); 
            break; 
          } 
          } 
        }catch (Exception e){ 
          Log.e("", e.getMessage()); 
        }   
        } 
      }.start(); 
      } 
     }); 

在發送文件時出現以下錯誤。

02:48:58 PM RCV (1079277904): <iq type="error" id="6gQg0-6" to="admin-pc/cc4dd310" from="[email protected]/Smack"><si xmlns="http://jabber.org/protocol/si" id="jsi_3030055238839806007" profile="http://jabber.org/protocol/si/profile/file-transfer"><file xmlns="http://jabber.org/protocol/si/profile/file-transfer" name="sdcard"><desc>test</desc></file><feature xmlns="http://jabber.org/protocol/feature-neg"><x xmlns="jabber:x:data" type="form"><field var="stream-method" type="list-single"><option><value>http://jabber.org/protocol/bytestreams</value></option><option><value>http://jabber.org/protocol/ibb</value></option></field></x></feature></si><error code="405" type="cancel"><not-allowed xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"/></error></iq> 
+0

你正在使用哪個版本的smack?有一個已知的文件傳輸問題3.2 – 2013-05-11 08:21:50

+0

我用ASMACK 17 – 2013-05-11 08:29:01

+0

應該沒問題... – 2013-05-11 08:30:37

回答

0

首先,您需要使用版本3.1或3.3,因爲有3.233的known issue。然後查看這articlethis one關於編碼所述傳輸的指導。希望這可以幫助。

+0

我不知道Smack 3.2的任何文件傳輸錯誤,這些錯誤並未使用3.2.1或3.2.2修復。沒有必要回退到較舊的版本。 – Flow 2013-05-11 14:22:38

+0

@FLow我發佈了一個鏈接 – 2013-05-11 15:35:01

+0

這個「主票」的所有子任務在3.2.1或3.2.2和SMACK-351固定的情況下已被標記爲3.3。再次,沒有必要使用舊版本。 3.2.2或3.3將正常工作。 – Flow 2013-05-11 15:42:22

相關問題