@cxm-2016
2016-09-22T16:15:50.000000Z
字数 618
阅读 1868
android
no
class NetStateReceiver : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent?) {
val net = NetUtils(context)
Urls.networkState = net.NETWORK_TYPE
Log.e("NetState", "${Urls.networkState.name}")
}
}
<receiver android:name=".component.broadcast.NetStateReceiver">
<intent-filter>
<action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
</intent-filter>
</receiver>
override fun onCreate() {
...
val receiver = NetStateBroadCast()
val filter = IntentFilter()
filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION)
registerReceiver(receiver, filter)
}