如何在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>
你正在使用哪個版本的smack?有一個已知的文件傳輸問題3.2 – 2013-05-11 08:21:50
我用ASMACK 17 – 2013-05-11 08:29:01
應該沒問題... – 2013-05-11 08:30:37