I have implemented a provision for chat in my app.The chat works using socket.io .I am trying to resolve the issue of the emitter listeners working properly when internet goes off and comes back on.Currently , the socket gets re-connected on the internet but listeners don't work at all once the internet is connected back.Please help guys!
Asked
Active
Viewed 1,038 times
1 Answers
0
You can listen a connectivity change and do again the connection?
In your manifest:
<receiver android:name=".ConnectivityReceiver"
android:label="NetworkConnection">
<intent-filter>
<action android:name="android.net.conn.CONNECTIVITY_CHANGE"/>
</intent-filter>
</receiver>
And the ConnectivityReceiver code something like:
public class ConnectivityReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeNetInfo = connectivityManager.getActiveNetworkInfo();
if ( activeNetInfo != null )
{
//do your reconection if it's lost
}
}

David
- 150
- 1
- 10