4

I am just trying to transfer a file through xmpp.I am using asmack lib.I am getting exception below.

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)

can anybody help me how can i do a file transfer in android using asmack?

Martín Schonaker
  • 7,273
  • 4
  • 32
  • 55
Hitendra
  • 3,218
  • 7
  • 45
  • 74

2 Answers2

4

you have to make a dummy service discovery manager.

new ServiceDiscoveryManager(your XMPP connection);

now this line does not cause any problems.

mFileTransferManager = new FileTransferManager(your XMPP connection);

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

push smack.properties into "/data/" folder.

Modify initialize() method of ProviderManager.java (it's in org/jivesoftware/smack/provider) as follows.

Find the following line.

        Enumeration providerEnum = classLoader.getResources(
                "/META-INF/smack.providers");

Replace it with

        Enumeration providerEnum = classLoader.getResources(
                "/data/smack.providers");

Hope this help

Synxmax
  • 2,226
  • 1
  • 22
  • 38
  • I am following the tutorial from this site. http://davanum.wordpress.com/2008/12/29/updated-xmpp-client-for-android/ Now i have implemented new ServiceDiscoveryManager(your XMPP connection); for that i am getting following exception.I cant find the Enumeration in all three classess.I m using asmack-jse and i dont know the version but i have downloaded it from code.google. I/System.out( 507): Status :: Error Error :: null Exception :: feature-not-implemented(501) I/System.out( 507): Is it done? true – Hitendra Jun 14 '11 at 08:59
  • is this happen when u compile that tutorial ? – Synxmax Jun 15 '11 at 06:23
  • yes, i have just add one line as you said new ServiceDiscoveryManager(your XMPP connection); and there are three classess ,within those i cant find Enumeration. – Hitendra Jun 15 '11 at 06:28
  • with which version of android SDK ?! – Synxmax Jun 15 '11 at 06:41
  • android 2.2-froyo ,can u please join any of the chat room? – Hitendra Jun 15 '11 at 06:47
  • @Hitendra sorry fella i am on a little trip , as fast as i can get my hand on a keyboard sure i do if you didn't solve it yet ( i'm mobile ) – Synxmax Jun 22 '11 at 06:54
  • @Hitendra did you solved the issue.i am facing the same problem. and where do i find smack.properties on this link http://www.igniterealtime.org/downloads/source.jsp – Juned Aug 09 '12 at 09:54
  • @Synxmax can you check my this question http://stackoverflow.com/questions/11666963/file-is-not-being-transferred-in-smack-api – Juned Aug 09 '12 at 09:57
  • how do i copy smack.properties on emulator? can you be more specific. i didn't find any properties on given link. – Juned Aug 16 '12 at 05:45
  • from where can i found smack.propertise file i have seen that link also download source but not able to find the given file – Khan Sep 08 '12 at 05:50
  • @Synxmax I am facing problem in sharing file. Can you see over this [link](http://stackoverflow.com/q/28271210/4358880) and tell what mistake I am making – Android Rockss Feb 02 '15 at 07:58
2

Please use this one for file transfer in asmack. I have done this and have checked it. Its working perfect.

to receive a file use this method

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

just ask me if you have any queries regarding file transfer in xmpp using asmack lib.

Thanks

Gaurav Arora
  • 8,282
  • 21
  • 88
  • 143
  • @Gaurav Arora .. can u please tell me how to send or recieve file over xmpp in android.. I am kind off stucked in this file transfer.. – Udit Kapahi Sep 20 '13 at 13:36
  • @UditKapahi I have already described above, Let me know if you have any problem implementing the same. – Gaurav Arora Sep 21 '13 at 11:10
  • @gaurav arora : first problem...my app is not connecting to ftp port ie 7777 when i changed my port from 5222 – Udit Kapahi Sep 22 '13 at 06:23
  • @gaurav arora: can you give me our email id i can describe my problem over there very well – Udit Kapahi Sep 22 '13 at 06:24
  • 1
    @UditKapahi come over gaurav.arora90@gmail.com – Gaurav Arora Sep 24 '13 at 07:26
  • @GauravArora, hi there, i am having problem with same implementation, my user on another end doesn't have option to send file,,,, I am not gettting where to start the listener for file transfer.... – Abdul Wahab Oct 01 '14 at 07:56
  • @Gourav Arora I tried your code to receive file, but I am unable to receive file. The code I used is [this.](http://paste.ofcode.org/B9tcXj2Aie9ajBfunn4cqy) I am able to receive messages when there is any incomming mesage but not able to receive the log Log.i("File transfere manager", "created"); when there is any incomming file – nawaab saab Jan 29 '15 at 12:57
  • @GauravArora I am facing problem in sharing file. Can you see over this [link](http://stackoverflow.com/q/28271210/4358880) and tell what mistake I am making – Android Rockss Feb 02 '15 at 07:57
  • @GauravArora I have tried this code its working fine in same network but failed while i have used different network. – Ajay Aug 12 '16 at 14:14