Search code examples
androidnetwork-programmingevent-handlingandroid-broadcastreceiverandroid-7.0-nougat

Handle network changes on android 7 Nougat


Is there any way to handle wi-fi or cellular networks enable/disable on android N. I've tried to add broadcast receiver with intent-filter "android.net.conn.CONNECTIVITY_CHANGE", but it's deprecated for N and higher.


Solution

  • The network changes listener implementation for android N and high

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
        registerReceiver(mNetworkReceiver, 
            new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION));
    }
    

    Many thanks to CommonsWare for useful answer.