0

I'm trying to make broadcast receiver that listen to internet connectivity and then do some tasks when connected.

I do not receive any notification when I disable or enable my WIFI on my real device or disable/enable the data access in emulator. the action CONNECTIVITY_CHANGE is no longer supported.

  public class InternetConnectivityReceiver extends BroadcastReceiver {
Context context;
@Override
public void onReceive(Context context, Intent intent) {
    this.context = context;

    Log.i(TAG, "Internet Conenction State Changed");
}
}

Manifest

 <application
    android:icon="@android:drawable/arrow_down_float"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >



      <receiver android:name=".InternetConnectivityReceiver">
            <intent-filter>
                <action android:name="android.net.conn.BACKGROUND_DATA_SETTING_CHANGED">

                </action>
            </intent-filter>
        </receiver>
......
</application>
MSaudi
  • 4,442
  • 2
  • 40
  • 65
  • possible duplicate: http://stackoverflow.com/questions/3307237/how-can-i-monitor-the-network-connection-status-in-android – Anis BEN NSIR Sep 26 '12 at 14:06
  • have you given internet permissions ? – Lucifer Sep 26 '12 at 14:29
  • Yes, permissions are given. I tried to register dynamically on code and it's working but when activity finished, it does not listen any more. That means in general that the permissions are fine – MSaudi Sep 26 '12 at 14:37

1 Answers1

0

Developer documentation for ConnectivityManager says:

BACKGROUND_DATA_SETTING_CHANGED

This constant is deprecated. As of ICE_CREAM_SANDWICH, availability of background data depends on several combined factors, and this broadcast is no longer sent.

Try listening for "android.net.conn.CONNECTIVITY_CHANGE" instead.

David Wasser
  • 93,459
  • 16
  • 209
  • 274
  • Oh, I think I get it wrong or it was written wrong some where. I thought android.net.conn.CONNECTIVITY_CHANGE is the one whic was deprecated as also I can't find it in the auto complete. Thanks so much, this worked. – MSaudi Sep 26 '12 at 15:08