asmack android,无法传输文件

发布于 2024-11-28 09:23:53 字数 1654 浏览 1 评论 0原文

我无法使用 smack 传输文件,我在一侧使用 android 模拟器,在另一侧使用 Spark。当我进行传输时,应用程序强制关闭,并显示以下错误消息和文件传输请求的通知,在接受文件后,传输文件时出错。错误日志粘贴在下面。

我搜索了不同的解决方案,其中之一说:

首先,您必须将 smack.properties 复制到您的 Android 模拟器。 您可以在原始 SMACK API 站点获取 smack.properties。

http://www.igniterealtime.org/downloads/source.jsp< /p>

我打开了该网站并下载了smack的源代码,但无法在任何地方找到smack.properties。 第一选择已关闭。

提出的第二个解决方案是更改我无法找到的 org.jivesoftware.smackx.filetransfer.Socks5TransferNegotiator.discoverLocalIP() 中的 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)

I am unable to transfer file using a smack, I am using android emulator on one side and spark on the other. When I do transfer the application force closes with the following error messages and a notification of file transfer request, after accepting the file, there was an error transfering the file.error log is pasted below.

I searched different solution and one of them says:

First, you have to copy a smack.properties to you android emulator.
You can get smack.properties at the original SMACK API site.

http://www.igniterealtime.org/downloads/source.jsp

I opened the site and downloaded the source code of smack but unable to find smack.properties anywhere.
1st choice closed.

Second solution proposed was to change the implementation of discoverLocalIP() in org.jivesoftware.smackx.filetransfer.Socks5TransferNegotiator.discoverLocalIP() which I am unable to find.

How can i transfer file?


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)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦明 2024-12-05 09:23:53

@hunt 创建以下函数来配置提供程序 Mager 并在发送文件之前调用它。

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());

}

@hunt Create the following function to configure provider mager and call it before the file is sent.

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());

}
云裳 2024-12-05 09:23:53

配置文件位于

resources/META-INF/

您需要的文件下,

smack-config.xml
smack.providers

您的具体错误是由于尚未使用 smack.providers 文件配置 ProviderManager 引起的。这会导致传入数据包被读入默认的 PacketExtension,而不是为特定节类型配置的数据包。

如果您使用 asmack,我认为这已经可以处理了。如果是常规 Smack,您将必须配置 ProviderManager 以从正确的位置读取文件。

我认为您可以通过扩展 ProviderManager 并覆盖 initialize() 方法来做到这一点。基本上复制现有的,但指定 android 资源目录而不是 META-INF 目录。已经有一个 Jira 任务针对此问题来使目录可配置,但尚未解决。

此外,文件传输中存在一个错误,已在最新版本(3.2.1)中修复。

The config files are under

resources/META-INF/

The ones you will need are

smack-config.xml
smack.providers

Your specific error is caused by the fact that the ProviderManager has not been configured with the smack.providers file. This results in the incoming packets being read into the default PacketExtension instead of the one configured for the specific stanza type.

If you are using asmack, I would think that would be handled already. If regular Smack, you will have to configure the ProviderManager to read the file from the right location.

I think you can do this by extending ProviderManager and overriding the initialize() method. Basically copy the existing one but specify the android resource directory instead of the META-INF one. There is already a Jira task against this to make the directory configurable, but it isn't resolved yet.

In addition, there was a bug in file transfer that was fixed in the latest version (3.2.1).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文