Reputation: 49
My question is, Is there any way to find out the network disconnected time? when will it goes off or when will goes On mode?
Thanks in advance For any suggestion and help.
Upvotes: 0
Views: 122
Reputation: 2235
You can create a BroadcastReceiver
that listens to Intent
s with android.net.conn.CONNECTIVITY_CHANGE action.
public class ConnectivityListener extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
// There is action occured with network.
ConnectivityManager cm = (ConnectivityManager)context.getSystemService(
Context.CONNECTIVITY_SERVICE);
// query connectivity manager for network state.
}
}
Dont forget to declare this receiver in the AndroidManifest.xml:
<receiver android:name=".ConnectionChangeReceiver">
<intent-filter>
<action android:name="android.net.conn.CONNECTIVITY_CHANGE"/>
</intent-filter>
</receiver>
Upvotes: 1