Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 599
Arsen Nersisyan Avatar asked Oct 26 '16 15:10

Arsen Nersisyan


1 Answers

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.

like image 122
Arsen Nersisyan Avatar answered Oct 05 '22 01:10

Arsen Nersisyan