我无法使用smack传输文件,我在一边使用android模拟器,另一边使用spark。当我转移应用程序时,关闭并显示以下错误消息和文件传输请求通知,在接受文件后,传输文件时出错。下面粘贴了错误日志。
我搜索了不同的解决方案,其中一个说:
首先,你必须将smack.properties复制到你的android模拟器。 您可以在原始SMACK API站点获取smack.properties。
我打开了网站并下载了smack的源代码但无法在任何地方找到smack.properties
。
第一选择关闭。
建议的第二个解决方案是更改discoverLocalIP()
org.jivesoftware.smackx.filetransfer.Socks5TransferNegotiator.discoverLocalIP()
中我无法找到的实现。
我如何传输文件?
WARN/dalvikvm(4994): threadid=25: thread exiting with uncaught exception (group=0x4001b188)
ERROR/AndroidRuntime(4994): Uncaught handler: thread File Transfer jsi_8875615847496033183 exiting due to uncaught exception
ERROR/AndroidRuntime(4994): java.lang.ClassCastException: org.jivesoftware.smack.util.PacketParserUtils$2
ERROR/AndroidRuntime(4994): at org.jivesoftware.smackx.filetransfer.FileTransferNegotiator.negotiateOutgoingTransfer(FileTransferNegotiator.java:401)
ERROR/AndroidRuntime(4994): at org.jivesoftware.smackx.filetransfer.OutgoingFileTransfer.negotiateStream(OutgoingFileTransfer.java:359)
ERROR/AndroidRuntime(4994): at org.jivesoftware.smackx.filetransfer.OutgoingFileTransfer.access$100(OutgoingFileTransfer.java:35)
ERROR/AndroidRuntime(4994): at org.jivesoftware.smackx.filetransfer.OutgoingFileTransfer$2.run(OutgoingFileTransfer.java:214)
ERROR/AndroidRuntime(4994): at java.lang.Thread.run(Thread.java:1096)
答案 0 :(得分:2)
@hunt创建以下函数以配置提供者资格并在发送文件之前调用它。
public void configureProviderManager() {
ProviderManager pm = ProviderManager.getInstance();
// The order is the same as in the smack.providers file
// Private Data Storage
pm.addIQProvider("query","jabber:iq:private", new PrivateDataManager.PrivateDataIQProvider());
// Time
try {
pm.addIQProvider("query","jabber:iq:time", Class.forName("org.jivesoftware.smackx.packet.Time"));
} catch (ClassNotFoundException e) {
System.err.println("Can't load class for org.jivesoftware.smackx.packet.Time");
}
// Roster Exchange
pm.addExtensionProvider("x","jabber:x:roster", new RosterExchangeProvider());
// Message Events
pm.addExtensionProvider("x","jabber:x:event", new MessageEventProvider());
// Chat State
pm.addExtensionProvider("active","http://jabber.org/protocol/chatstates", new ChatStateExtension.Provider());
pm.addExtensionProvider("composing","http://jabber.org/protocol/chatstates", new ChatStateExtension.Provider());
pm.addExtensionProvider("paused","http://jabber.org/protocol/chatstates", new ChatStateExtension.Provider());
pm.addExtensionProvider("inactive","http://jabber.org/protocol/chatstates", new ChatStateExtension.Provider());
pm.addExtensionProvider("gone","http://jabber.org/protocol/chatstates", new ChatStateExtension.Provider());
// XHTML
pm.addExtensionProvider("html","http://jabber.org/protocol/xhtml-im", new XHTMLExtensionProvider());
// Group Chat Invitations
pm.addExtensionProvider("x","jabber:x:conference", new GroupChatInvitation.Provider());
// Service Discovery # Items
pm.addIQProvider("query","http://jabber.org/protocol/disco#items", new DiscoverItemsProvider());
// Service Discovery # Info
pm.addIQProvider("query","http://jabber.org/protocol/disco#info", new DiscoverInfoProvider());
// Data Forms
pm.addExtensionProvider("x","jabber:x:data", new DataFormProvider());
// MUC User
pm.addExtensionProvider("x","http://jabber.org/protocol/muc#user", new MUCUserProvider());
// MUC Admin
pm.addIQProvider("query","http://jabber.org/protocol/muc#admin", new MUCAdminProvider());
// MUC Owner
pm.addIQProvider("query","http://jabber.org/protocol/muc#owner", new MUCOwnerProvider());
// Delayed Delivery
pm.addExtensionProvider("x","jabber:x:delay", new DelayInformationProvider());
pm.addExtensionProvider("delay", "urn:xmpp:delay", new DelayInformationProvider());
// Version
try {
pm.addIQProvider("query","jabber:iq:version", Class.forName("org.jivesoftware.smackx.packet.Version"));
} catch (ClassNotFoundException e) {
System.err.println("Can't load class for org.jivesoftware.smackx.packet.Version");
}
// VCard
pm.addIQProvider("vCard","vcard-temp", new VCardProvider());
// Offline Message Requests
pm.addIQProvider("offline","http://jabber.org/protocol/offline", new OfflineMessageRequest.Provider());
// Offline Message Indicator
pm.addExtensionProvider("offline","http://jabber.org/protocol/offline", new OfflineMessageInfo.Provider());
// Last Activity
pm.addIQProvider("query","jabber:iq:last", new LastActivity.Provider());
// User Search
pm.addIQProvider("query","jabber:iq:search", new UserSearch.Provider());
// SharedGroupsInfo
pm.addIQProvider("sharedgroup","http://www.jivesoftware.org/protocol/sharedgroup", new SharedGroupsInfo.Provider());
// JEP-33: Extended Stanza Addressing
pm.addExtensionProvider("addresses","http://jabber.org/protocol/address", new MultipleAddressesProvider());
// FileTransfer
pm.addIQProvider("si","http://jabber.org/protocol/si", new StreamInitiationProvider());
pm.addIQProvider("query","http://jabber.org/protocol/bytestreams", new BytestreamsProvider());
pm.addIQProvider("open","http://jabber.org/protocol/ibb", new OpenIQProvider());
pm.addIQProvider("data","http://jabber.org/protocol/ibb", new DataPacketProvider());
pm.addIQProvider("close","http://jabber.org/protocol/ibb", new CloseIQProvider());
pm.addExtensionProvider("data","http://jabber.org/protocol/ibb", new DataPacketProvider());
// Privacy
pm.addIQProvider("query","jabber:iq:privacy", new PrivacyProvider());
// SHIM
pm.addExtensionProvider("headers", "http://jabber.org/protocol/shim", new HeadersProvider());
pm.addExtensionProvider("header", "http://jabber.org/protocol/shim", new HeaderProvider());
// PubSub
pm.addIQProvider("pubsub", "http://jabber.org/protocol/pubsub", new PubSubProvider());
pm.addExtensionProvider("create", "http://jabber.org/protocol/pubsub", new SimpleNodeProvider());
pm.addExtensionProvider("items", "http://jabber.org/protocol/pubsub", new ItemsProvider());
pm.addExtensionProvider("item", "http://jabber.org/protocol/pubsub", new ItemProvider());
pm.addExtensionProvider("subscriptions", "http://jabber.org/protocol/pubsub", new SubscriptionsProvider());
pm.addExtensionProvider("subscription", "http://jabber.org/protocol/pubsub", new SubscriptionProvider());
pm.addExtensionProvider("affiliations", "http://jabber.org/protocol/pubsub", new AffiliationsProvider());
pm.addExtensionProvider("affiliation", "http://jabber.org/protocol/pubsub", new AffiliationProvider());
pm.addExtensionProvider("options", "http://jabber.org/protocol/pubsub", new FormNodeProvider());
// PubSub owner
pm.addIQProvider("pubsub", "http://jabber.org/protocol/pubsub#owner", new PubSubProvider());
pm.addExtensionProvider("configure", "http://jabber.org/protocol/pubsub#owner", new FormNodeProvider());
pm.addExtensionProvider("default", "http://jabber.org/protocol/pubsub#owner", new FormNodeProvider());
// PubSub event
pm.addExtensionProvider("event", "http://jabber.org/protocol/pubsub#event", new EventProvider());
pm.addExtensionProvider("configuration", "http://jabber.org/protocol/pubsub#event", new ConfigEventProvider());
pm.addExtensionProvider("delete", "http://jabber.org/protocol/pubsub#event", new SimpleNodeProvider());
pm.addExtensionProvider("options", "http://jabber.org/protocol/pubsub#event", new FormNodeProvider());
pm.addExtensionProvider("items", "http://jabber.org/protocol/pubsub#event", new ItemsProvider());
pm.addExtensionProvider("item", "http://jabber.org/protocol/pubsub#event", new ItemProvider());
pm.addExtensionProvider("retract", "http://jabber.org/protocol/pubsub#event", new RetractEventProvider());
pm.addExtensionProvider("purge", "http://jabber.org/protocol/pubsub#event", new SimpleNodeProvider());
// Nick Exchange
pm.addExtensionProvider("nick", "http://jabber.org/protocol/nick", new Nick.Provider());
// Attention
pm.addExtensionProvider("attention", "urn:xmpp:attention:0", new AttentionExtension.Provider());
}
答案 1 :(得分:0)
配置文件在
下resources/META-INF/
你需要的是
smack-config.xml
smack.providers
您的特定错误是由于 ProviderManager 尚未配置 smack.providers 文件。这会导致传入的数据包被读入默认的 PacketExtension ,而不是为特定节类型配置的数据包。
如果您使用的是asmack,我认为已经处理过了。如果是常规Smack,则必须配置ProviderManager以从正确的位置读取文件。
我认为您可以通过扩展 ProviderManager 并覆盖 initialize()方法来实现此目的。基本上复制现有的一个,但指定android资源目录而不是META-INF。已经有一个针对此的Jira任务来使目录可配置,但它尚未解决。
此外,文件传输中存在最新版本(3.2.1)中修复的错误。