The problem:
The solution:
NetworkAvailability lets you register BroadcastReceiver
which works for pre-lollipop and lollipop devices as well.
You have to compile your project at least with AndroidSDK 21:
android{
compileSdkVersion 21
}
See ExampleActivity.