1
我在使用Smack Api和Oepnfire Server的Android應用程序中使用以下代碼進行文件傳輸。我沒有收到任何錯誤,但是問題是當我發送文件時,我在198行處得到取消狀態。有誰能夠幫助我? 。提前致謝 。Smack API問題
String to = mRecipient.getText().toString();
String text = mSendText.getText().toString();
// Uri uri = Uri.fromFile(new
// File("file:///android_asset/test.txt"));
if (new File("/data/data/" + getPackageName() + "/"
+ "test.txt").exists()) {
Log.d("XMPPClient File Exist", "exist");
}
SmackConfiguration.setPacketReplyTimeout(15000);
ConnectionConfiguration config = new ConnectionConfiguration(
"192.168.1.200", 5222);
// config.setRosterLoadedAtLogin(true);
// config.setSendPresence(true);
// config.setSASLAuthenticationEnabled(false);
config.setReconnectionAllowed(true);
connection = new XMPPConnection(config);
/*
* ConnectionConfiguration connConfig = new
* ConnectionConfiguration("192.168.1.200", 5222, "");
* connConfig.setReconnectionAllowed(true);;
*
* connection = new XMPPConnection(connConfig);
*/
try {
connection.connect();
} catch (XMPPException e2) {
// TODO Auto-generated catch block
e2.printStackTrace();
}
try {
connection.connect();
} catch (XMPPException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
// connection.login(userName, password);
ServiceDiscoveryManager servicemanager = ServiceDiscoveryManager
.getInstanceFor(connection);
if (servicemanager == null)
servicemanager = new ServiceDiscoveryManager(connection);
servicemanager
.addFeature("http://jabber.org/protocol/disco#info");
servicemanager.addFeature("jabber:iq:privacy");
// Log.d("XMPPClient Txt File", uri.toString());
try {
// Create the outgoing file transfer
manager = new FileTransferManager(connection);
FileTransferNegotiator.setServiceEnabled(connection, true);
OutgoingFileTransfer transfer = manager
.createOutgoingFileTransfer("[email protected]/Smack");
// Send the file
// getBaseContext().getAssets().open("Entity");
// OutgoingFileTransfer.setResponseTimeout(30000);
transfer.sendFile(new File("/data/data/" + getPackageName()
+ "/" + "test.txt"), "You won't believe this!");
while (!transfer.isDone()) {
try {
Thread.sleep(1000);
Log.i("transfere file", "sending file status "
+ transfer.getStatus() + "progress: "
+ transfer.getProgress());
if (transfer.getStatus() == org.jivesoftware.smackx.filetransfer.FileTransfer.Status.error) {
transfer.cancel();
Log.e("", transfer.getStatus().toString());
Log.e("", "EEEEEERRRRRRRROOORRRRR");
break;
}
} catch (InterruptedException e) {
// TODO Auto-generated catch block
Log.e("aaaaaaaaaaaaaaa", "aaaa" + e);
e.printStackTrace();
}
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}