openfire - How to create listener for send and receive file using SMACK in android? -
i want implement file transfer functionality in chat application have developed in android using smack , openfire.but got error in sending , receiving file.so can me solve problem.thanks in advance.
here following code receiving file.
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"); xmppconnection.debug_enabled = true; // create file transfer manager final filetransfermanager managerlistner = new filetransfermanager(connection); filetransfernegotiator.setserviceenabled(connection, true); log.i("file transfere manager", "created"); managerlistner.addfiletransferlistener(new filetransferlistener() { @override public void filetransferrequest(filetransferrequest request) { // todo auto-generated method stub 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("/mnt/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(org.jivesoftware.smackx.filetransfer.filetransfer.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: handle exception e.printstacktrace(); } catch (interruptedexception e) { // todo auto-generated catch block e.printstacktrace(); } } });
here following error have arise.
02:48:58 pm rcv (1079277904): <iq type="error" id="6gqg0-6" to="admin-pc/cc4dd310" from="2222222222@admin-pc/smack"><si xmlns="http://jabber.org/protocol/si" id="jsi_3030055238839806007" profile="http://jabber.org/protocol/si/profile/file-transfer"><file xmlns="http://jabber.org/protocol/si/profile/file-transfer" name="sdcard"><desc>test</desc></file><feature xmlns="http://jabber.org/protocol/feature-neg"><x xmlns="jabber:x:data" type="form"><field var="stream-method" type="list-single"><option><value>http://jabber.org/protocol/bytestreams</value></option><option><value>http://jabber.org/protocol/ibb</value></option></field></x></feature></si><error code="405" type="cancel"><not-allowed xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"/></error></iq>
the error occurs because missed add configuration of provider manager allows share files. please add following static code in provider manager class
// 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());
also add following property open fire server enable file sharing.
xmpp.proxy.enabled =true xmpp.proxy.externalip =your public ip xmpp.proxy.port =7777
this work you.
Comments
Post a Comment