通过XMPP在Android中进行文件传输?

| 我只是试图通过xmpp传输文件,我正在使用asmack lib。我在下面遇到异常。
E/AndroidRuntime(  332): FATAL EXCEPTION: main
E/AndroidRuntime(  332): java.lang.NullPointerException
E/AndroidRuntime(  332):        at org.jivesoftware.smackx.bytestreams.socks5.Socks5BytestreamManager.enableService(Socks5BytestreamManager.java:704)
E/AndroidRuntime(  332):        at org.jivesoftware.smackx.bytestreams.socks5.Socks5BytestreamManager.activate(Socks5BytestreamManager.java:696)
E/AndroidRuntime(  332):        at org.jivesoftware.smackx.bytestreams.socks5.Socks5BytestreamManager.getBytestreamManager(Socks5BytestreamManager.java:1
80)
E/AndroidRuntime(  332):        at org.jivesoftware.smackx.filetransfer.Socks5TransferNegotiator.<init>(Socks5TransferNegotiator.java:50)
E/AndroidRuntime(  332):        at org.jivesoftware.smackx.filetransfer.FileTransferNegotiator.<init>(FileTransferNegotiator.java:217)
E/AndroidRuntime(  332):        at org.jivesoftware.smackx.filetransfer.FileTransferNegotiator.getInstanceFor(FileTransferNegotiator.java:102)
E/AndroidRuntime(  332):        at org.jivesoftware.smackx.filetransfer.FileTransferManager.<init>(FileTransferManager.java:63)
E/AndroidRuntime(  332):        at org.apache.android.xmpp.XMPPClient.fileTransfer(XMPPClient.java:143)
E/AndroidRuntime(  332):        at org.apache.android.xmpp.XMPPClient.onClick(XMPPClient.java:200)
E/AndroidRuntime(  332):        at android.view.View.performClick(View.java:2408)
E/AndroidRuntime(  332):        at android.view.View$PerformClick.run(View.java:8816)
E/AndroidRuntime(  332):        at android.os.Handler.handleCallback(Handler.java:587)
E/AndroidRuntime(  332):        at android.os.Handler.dispatchMessage(Handler.java:92)
E/AndroidRuntime(  332):        at android.os.Looper.loop(Looper.java:123)
E/AndroidRuntime(  332):        at android.app.ActivityThread.main(ActivityThread.java:4627)
E/AndroidRuntime(  332):        at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(  332):        at java.lang.reflect.Method.invoke(Method.java:521)
E/AndroidRuntime(  332):        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
E/AndroidRuntime(  332):        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
有人可以帮助我如何使用asmack在android中进行文件传输吗?     
已邀请:
        您必须创建一个虚拟服务发现管理器。
new ServiceDiscoveryManager(your XMPP connection);
现在此行不会引起任何问题。
mFileTransferManager = new FileTransferManager(your XMPP connection);
首先,您必须将smack.properties复制到您的android模拟器。 您可以在原始的SMACK API网站上获得ѭ3。 http://www.igniterealtime.org/downloads/source.jsp 将smack.properties推送到\“ / data / \”文件夹中。 修改
ProviderManager.java
initialize()
方法(在
org/jivesoftware/smack/provider
中)。 查找以下行。
        Enumeration providerEnum = classLoader.getResources(
                \"/META-INF/smack.providers\");
替换为
        Enumeration providerEnum = classLoader.getResources(
                \"/data/smack.providers\");
希望有帮助     
        请使用此文件在asmack中进行文件传输。我已经完成并检查了。它的工作完美。 接收文件使用此方法
public void ReceiveFile() {
        Thread thread = new Thread() {
            public void run() {
               ServiceDiscoveryManager sdm = ServiceDiscoveryManager
                        .getInstanceFor(connection);

                if (sdm == null)
                    sdm = new ServiceDiscoveryManager(connection);

                sdm.addFeature(\"http://jabber.org/protocol/disco#info\");

                sdm.addFeature(\"jabber:iq:privacy\");

                // Create the file transfer manager
                final FileTransferManager managerListner = new FileTransferManager(
                        connection);

                FileTransferNegotiator
                        .setServiceEnabled(connection, true);

                Log.i(\"File transfere manager\", \"created\");

                // Create the listener
                managerListner
                        .addFileTransferListener(new FileTransferListener() {
                            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());

IncomingFileTransfer transfer = request.accept();

                Log.i(\"Recieve File alert dialog\", \"accepted\");
                try {


                    transfer.recieveFile(new File(\"/sdcard/\"
                            + request.getFileName()));

        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(Status.error)) {
                                // Log.i(\"Error file\",
                                // transfer.getError().getMessage());
                                Log.i(\"Recieve File alert dialog\",
                                        \"cancelling still receiving : \"
                                                + (transfer.getProgress())
                                                + \" status \"
                                                + transfer.getStatus());
                                transfer.cancel();

                                break;
                            }

                    }

} catch (XMPPException e) {

                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (InterruptedException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                        });

            }
        };
        thread.start();
    }
只要问我是否对使用asmack lib的xmpp文件传输有任何疑问。 谢谢     

要回复问题请先登录注册