Im trying to receive BroadcastMessages from CONNECTIVITY_ACTION:
// register BroadcastReceiver on network state changes
final IntentFilter mIFNetwork = new IntentFilter();
mIFNetwork.addAction(android.net.ConnectivityManager.CONNECTIVITY_ACTION); //"android.net.conn.CONNECTIVITY_CHANGE"
registerReceiver(mIRNetwork, mIFNetwork);
and receiver is:
private BroadcastReceiver mIRNetwork = new BroadcastReceiver() {
@Override
public void onReceive(final Context context, final Intent intent) {
android.util.Log.i(TAG,"mIRNetwork: Network State Received: "+intent.getAction());
Bundle extras = intent.getExtras();
if (extras!=null){
android.util.Log.i(TAG,"mIRNetwork: ACTION_BACKGROUND_DATA_SETTING_CHANGED: "+extras.getString(ConnectivityManager.ACTION_BACKGROUND_DATA_SETTING_CHANGED));
android.util.Log.i(TAG,"mIRNetwork: CONNECTIVITY_ACTION: "+extras.getString(ConnectivityManager.CONNECTIVITY_ACTION));
android.util.Log.i(TAG,"mIRNetwork: EXTRA_EXTRA_INFO: "+extras.getString(ConnectivityManager.EXTRA_EXTRA_INFO));
android.util.Log.i(TAG,"mIRNetwork: EXTRA_NO_CONNECTIVITY: "+extras.getString(ConnectivityManager.EXTRA_NO_CONNECTIVITY));
android.util.Log.i(TAG,"mIRNetwork: EXTRA_REASON: "+extras.getString(ConnectivityManager.EXTRA_REASON));
}
}
in short extras is always null. I thought that if i loose WiFi connection i should get EXTRA_NO_CONNECTIVITY (cuz its the only way to Internet) or at least something from the list. But no luck. If i disconnect my WiFi AP receiver gets his message but with null extras. When i turn my WiFi back on once again receiver fires but no extras... Why is that? How to know that app lost any network connection? I thought its the way.
if(!action.equals(ConnectivityManager.CONNECTIVITY_ACTION))
can't understand this when the only action added to filter is CONNECTIVITY_ACTION? – Cardoso