Try this method.
registerReceiver(networkBroadcastReceiver, new IntentFilter("android.net.conn.CONNECTIVITY_CHANGE"));
You will get call here once connectivity changed.
BroadcastReceiver networkBroadcastReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
count++;
}
};
12
solved How to count the number of times internet connectivity change in a android application [duplicate]