user1300242
user1300242

Reputation: 49

Is there any way to find out when will network goes to disconnected in Android?

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

Answers (1)

pepyakin
pepyakin

Reputation: 2235

You can create a BroadcastReceiver that listens to Intents 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

Related Questions