I am creating a chat app using smack using openfire sever by XMPP protocol. I can chat with other user and working well. I created connection in Service class. So i am able to get notification message when i am not in my application but i get my service is restarting again and again when network problem, network change, network slow etc. So my connection is lost. and user is not always able to chat.
So i solved connection problem. like as
if( service is not runing)
start my service
else
if(connection is NULL or not Connected)
reconnection . so my connection is created
My service class:-
if(connection is NULL or not connected)
reconnect. so my connection is created
else
not connected.
But now if my service is runing and connection is lost. and i open my application , a new connection is created. This connection is created by application not services. So now when i am not in my app , i did not get any notification for incoming message because incoming message was coming by service connection.
Now i have involved. please expert help me. How can i solve?
Is there way for push notification in openfire?
You could try binding to your service;
Create a method in your service called connect()
When the application is started instead of creating a connection object in activity class, bind to the service, call myServcie.connect();
This way the connection is still owned by the service,
Other way to communicate with the service is via intents.... send an intent to the service when activity is created and have the BroadcastReceiver in the Service call connect();
One thing to watch out for is continuously reconnecting in a mobile environment is not recommended.... battery life being what it is. You can check to see if the application package is the one that is showing and then reconnect if it is etc.
James
Related
I have a service that runs every min to check if the global XMPPConnection object is connected and authenticated. What I found is that after an hour or so of idle mode, the connection object shows it is connected and authenticated but it does not receive any messages.
The connection seems to be broken without the Connection object knowing about it. Please let me know what I could implement to check if the XMPPConnection object is truly connected and can receive messages even after a long while of inactivity.
Appreciate your help.
hi If you are using openfire then go to Server settings then Client connection and change settings to Do not disconnect clients that are idle.
This help you to user available all times.
Second solution for your problem if you are not using any service for making user online. Then do that thing.
Here i made example of one to one chat and it available on github.
thanks hope this help you.
Depends on your XMPP server implementation, you can simply send message to yourself and check if you receive it.
Another way would be to perform XMPP service discovery, fetch your roster list etc. in short - do something that requires client-server communication.
I am developing an application using BluetoothGatt class and API for android devices. Application has a feature where user can disconnect one device and connect with another bluetooth device. Basically user can add or remove devices in the app.
To achieve this when user adds a new BLE device i use the same BluetoothGatt object to first disconnect the old device and than connect the new device.
Connection happens nicely but when i start reading characteristics of that device most of the time i get an error something like No Connection for "Bluetooth Address". And when i inspected the BluetoothGatt object is status is Busy.
I am really clueless on what wrong i am doing , can any body help me to understand what wrong i am doing.
Just to mention if i use only one device than everything is working fine.
I fixed this problem, i was using a service to initialize , connect gatt client object , and also the same service for processing data received from gatt client.
So intead of disconnecting and connecting the gatt client again , i unbinded the service , which made sure the gatt client is disconnected and closed. For new device connection i created a new service.
This is now working fine !!
I have created a chat application. My Service has a connection which I used in my application. when an incoming message arrives then it proves that Service class's connection with the server is alive. When my network connection has failed then the connection with the server is disconnected but the Service is still running.
Is there a way to ensure that my connection with the server will be alive for all time? If any network problem is found, how do I make sure it is automatically re-established within the Service.
Thank you.
I'm developing a queue of messages for a messenger app.
On Android if the connection is lost, messages is save on the queue and as soon as the 3G or wifi is back the messages go out of the queue. This is possible thanks I'm listening a broadcast receiver which alert me when the connection is back.
Is there anything similar on iOS?
Any workaround on iOS to achieve this behaviour?
You determine the restoration of an internet connection via the Reachability class. You can attempt resending once Reachability tells you that you have an Internet connection again.
I have developed one application which talks to the server to send and receive data, for that we have implemented activities and one background service so each activity has to register with the service when it needs to send any request so service will further forward that request to the server via Wi-Fi router.we have established socket connection with the server and data flows through it.
Problem: when device goes to sleep mode and after some time if you turns on device my app is disconnected from the server and in logcat following exception comes:
SntpClient(789): request time failed: java.net.SocketTimeoutException: Try again
I would like to know why this exception comes and how to resolve it.