Asmack android file trasfer problem

Hi, I’m trying to setup a basic test sample of file transfer useing SIP XEP-0096 XMPP extension.

for may test case I run openfire on CentOS6.4-64Bit Virtual Box. iptables is off.

Storage solution is based on DB (mysql).

It seems that receiver doesn’t negotiates well with the sender, Could you please have a look at logcats and my sample code(Attached)?

Sender LogCat Main Part:


Receiver LogCat:

03-04 20:00:12.638: I/System.out(11605): ??:??:?? بعدازظهر RCV (1319091388): avatar1.png

I’m working on a customized version of Xabber Client (

Please look at Provider method invokatins in OnCreate Activity if I missed something.

I define a FileTransferLister acccording to a tutorial from the link bellowm if I didn’t miss any part.: /

Any help or idea would be appreciated

I aim to put a step by step guid as a document in this forum, maybe usefull for feautures.

Best Regards


Thanks a lot. (1137 Bytes) (613 Bytes) (4060 Bytes)

I Triied again and put change FileTransferLister to code bellow, but no Log was outputed, it seems Listener is

not even invoke when a file-transfer query received!

public void fileTransferListener()


FileTransferManager manager = new FileTransferManager(connection);

manager.addFileTransferListener(new FileTransferListener() {


public void fileTransferRequest(FileTransferRequest request)


Log.i(“FILE TRANSFER Listener”,“New File Recived”); //this part is not exected!!!




Finally Sender get this error:

03-04 21:26:29.518: I/FILE TRANSFER(12121): refused cancelled error The remote user did not respond or the connection timed out.

what other info do you need for better inspection and resolving issue?

Thanks for your kind support

After some and debug, I reach final solution for file trasfer just worked as expected :wink:

This is the solution worked for me:

1- make connection configuration:

public void setConnectionConfig(View view)


EditText editText = (EditText) findViewById(;

HOST = editText.getText().toString();




showMessage(“invalid HOST”);



XMPPConnection.DEBUG_ENABLED = true;

connConfig = new AndroidConnectionConfiguration(HOST, PORT, SERVICE);

Log.i(“onCreate”,“Creating Connection Configuration DONE :-).”);

showMessage(“Creating Connection Configuration DONE :-).”);

connection = new XMPPConnection(connConfig);

Log.i(“makeConnection”, “XMPP Connection Created”);

showMessage(“Connection Created”);


2- Make Connection:

//Create Connection to XMPP Server

public void makeConnection(View view)




Log.e(“makeConnection”, “first configure connection”);

//showMessage(“first configure connection”);



new Thread( new Runnable()



public void run() {

// TODO Auto-generated method stub



Log.e(“makeConnection”, "Already Connected to "+ connection.getHost());

//showMessage("Already Connected to "+ connection.getHost());

return ;


//connection already initialized outside

try {

Log.i(“makeConnection”, “Try Make connection”);

//showMessage("Try Make connection to "+ connection.getHost());


if(connection!=null && connection.isConnected())


Log.i(“makeConnection”,“Connection Established! :-)”);

//showMessage("Connection Established to "+ connection.getHost());


} catch (XMPPException ex) {

Log.e(“makeConnection”, "Failed to connect to "+ connection.getHost());

//showMessage("Failed to connect to "+ connection.getHost());

Log.e(“makeConnection”, ex.toString());







3- Login to Server:

//Login to XMPP Server

public void loginAccount(View view)


if(connection==null || !connection.isConnected())


Log.e(“loginAccount”, " first try connect to Server: "+ HOST);

showMessage("First try connect to Server: "+HOST);




else if(!connection.getUser().equals(""))


Log.e(“loginAccount”, " already connected as : "+ connection.getUser());

showMessage( " already connected as : "+ connection.getUser());



EditText editText = (EditText) findViewById(;

USERNAME = editText.getText().toString();


editText = (EditText) findViewById(;

PASSWORD = editText.getText().toString();

try {


showMessage("Logined As “+USERNAME+” to "+connection.getHost());

Log.i(“loginAccount”, "Logined As “+USERNAME+” to "+connection.getHost());



} catch (XMPPException ex) {

Log.e(“loginAccount”, "Failed to login to "+ connection.getHost());

Log.e(“loginAccount”, ex.toString());




Log.e(“loginAccount”, "max retries reached to connect "+ connection.getHost());

showMessage("Failed to login to "+connection.getHost());







4- Here are 2 Assistant Methods I use:

public void configure(ProviderManager pm) {

// Private Data Storage

pm.addIQProvider(“query”, “jabber:iq:private”,

new PrivateDataManager.PrivateDataIQProvider());

// Time

try {

pm.addIQProvider(“query”, “jabber:iq:time”,


} catch (ClassNotFoundException e) {


“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



new ChatStateExtension.Provider());



new ChatStateExtension.Provider());



new ChatStateExtension.Provider());



new ChatStateExtension.Provider());



new ChatStateExtension.Provider());


    pm.addExtensionProvider("html", "[](",

new XHTMLExtensionProvider());

// Group Chat Invitations

pm.addExtensionProvider(“x”, “jabber:x:conference”,

new GroupChatInvitation.Provider());

// Service Discovery # Items

    pm.addIQProvider("query", "[](",

new DiscoverItemsProvider());

// Service Discovery # Info

    pm.addIQProvider("query", "[](",

new DiscoverInfoProvider());

// Data Forms

pm.addExtensionProvider(“x”, “jabber:x:data”, new DataFormProvider());

// MUC User

    pm.addExtensionProvider("x", "[](",

new MUCUserProvider());

// MUC Admin

    pm.addIQProvider("query", "[](",

new MUCAdminProvider());

// MUC Owner

    pm.addIQProvider("query", "[](",

new MUCOwnerProvider());

// Delayed Delivery

pm.addExtensionProvider(“x”, “jabber:x:delay”,

new DelayInformationProvider());

// Version

try {

pm.addIQProvider(“query”, “jabber:iq:version”,


} catch (ClassNotFoundException e) {

// Not sure what’s happening here.


// VCard

pm.addIQProvider(“vCard”, “vcard-temp”, new VCardProvider());

// Offline Message Requests

    pm.addIQProvider("offline", "[](",

new OfflineMessageRequest.Provider());

// Offline Message Indicator



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



new SharedGroupsInfo.Provider());

// JEP-33: Extended Stanza Addressing



new MultipleAddressesProvider());

// FileTransfer

    pm.addIQProvider("si", "[](",

new StreamInitiationProvider());

    pm.addIQProvider("query", "[](",

new BytestreamsProvider());

// Privacy

pm.addIQProvider(“query”, “jabber:iq:privacy”, new PrivacyProvider());

    pm.addIQProvider("command", "[](",

new AdHocCommandDataProvider());



new AdHocCommandDataProvider.MalformedActionError());



new AdHocCommandDataProvider.BadLocaleError());



new AdHocCommandDataProvider.BadPayloadError());



new AdHocCommandDataProvider.BadSessionIDError());



new AdHocCommandDataProvider.SessionExpiredError());


void startListener(final View view)


FileTransferManager manager = new FileTransferManager(connection);

final Intent resultIntent = new Intent(this, FileTransferRequestActivity.class);

final IncomingFileTransferWrapper transferWrapper = new IncomingFileTransferWrapper();

manager.addFileTransferListener(new FileTransferListener()



public void fileTransferRequest(final FileTransferRequest request)


Log.i(“FileListener”,“It Seems something is sent to me! :-O”);

final NotificationCompat.Builder mBuilder =new NotificationCompat.Builder(getApplicationContext())



.setContentText("File Transfer Request From “+request.getRequestor()+” - "+request.getFileName());


// Gets an instance of the NotificationManager service

final NotificationManager mNotifyMgr =(NotificationManager) getSystemService(NOTIFICATION_SERVICE);

final int myNotificatioID=mNotificationId;


new Thread(){


public void run() {

int progressBarStatus=0;

Log.i(“FileListener”,“Inside Thread Run”);

//showMessage(“It Seems something is sent to me! :-O”);

// startActivityForResult(resultIntent,FILE_TRANSFER_REQUEST_CODE);

File mf = Environment.getExternalStorageDirectory();

ReceivedFiledDirectory=Environment.getExternalStorageDirectory().getAbsolutePat h();



File file = new File(ReceivedFiledDirectory +"/"+ transferWrapper.transfer.getFileName());







}catch (Exception e) {

Log.e("", e.getMessage());


if(transferWrapper.transfer.getStatus().equals(Status.error)) {

Log.e("ERROR!!! ", transferWrapper.transfer.getError() + “”);


if(transferWrapper.transfer.getException() != null) {



progressBarStatus=(int)(100 * transferWrapper.transfer.getProgress());

mBuilder.setProgress(100, progressBarStatus, false);


mBuilder.setContentText("%"+progressBarStatus+" Transfered");

// Builds the notification and issues it.



// ok, file is downloaded,

if (progressBarStatus >= 100)


// sleep 2 seconds, so that you can see the 100%

try {


} catch (InterruptedException e) {



// When the loop is finished, updates the notification

mBuilder.setContentText(“Transfer complete”)

// Removes the progress bar



// close the progress bar dialog



}catch (Exception e) {

Log.e(“File Transfer Listener”,“Exit Thread”);







Please Like This Thread and Mark as Answered If this solution worked for you.

I’ll make a document of file transfer issues as soon as I have time.

Best Regards

1 Like

Is the problem related to ??

In any case, it’d be better, if you just post your solution instead of keep it in PMs.


I know, and I’ll make a document on it soon,

at the time I’m so busy, and because of integration, I couldn’t post the whole solution,

But I’ll make a sample project, and implement simple file tarnsfer solution there for android using asmack, to be helpfull for others.

I’ll try to work on different situations that will cause problem and make a list to resolve each problem by help of other people who faces problems with file tarnsfer on android.

As you could see my problem was somthing else: The Receiver receives file transfer query but had no reaction, Listener didn’t triggered.

1 Like

I am facing problem 503-service unavailable Error during file transfer openfire


I am developing chatting application in android with openfire server &asmack-jse-buddycloud.jar i am suffering to transfer files from one mobile to another mobile i refer the code from here link comment-page-1/#comment-5365

Pls ping me solution in my below email address,

Thanks & Regards



You don’t need to configure the provider manager. Also how is this different from the existing documentation (e.g. filetransfer.html )?

Thanks a lot Flow,

It’s strange because I have’t find that document at time I was working on file transfer after hours of searching!!!

I Think when ommit config provider, I faced with service unavailble error from the other client in bytestream mode.

It seems some parts like file transfer looks different when come to android asmack client according to my experience.

Also enabling File Transfer Proxy in OpenFire sever is a good practice to overcome some issues caused by networing structure and NAT in ByteStream Socks5 file transfer.

Hi, i am also trying to establish p2p communications between ipcamera and android device . i am getting the response from camera. like

how can i parse these values in my android code. The xmpp libjingle library provide any methods for this.?

How can i re transfer the packet to camera.Any one can help me please.