DanMD DanMD - 1 year ago 371
Android Question

Android N not sending android.net.conn.CONNECTIVITY_CHANGE broadcast?

I have defined a receiver in a sandbox Android N application:

<action android:name="android.net.conn.CONNECTIVITY_CHANGE" />

It's rather simple:

public class NetworkReceiver extends BroadcastReceiver {
private static final String TAG = NetworkReceiver.class.getName();
public void onReceive(Context context, Intent intent) {
Log.i(TAG, "Received Network Change event.");

This receiver is working fine if in my build.gradle file my targetSdkVersion is 23. However, if I set my targetSdkVersion to 24, the receiver never receives anything. In fact if I place a debug break point in my receiver Android Studio gives me the visual indication that it looks like the class is never even loaded into memory.

Did I miss something very basic in the Android N documentation? Is there a new way to detect connectivity change events?

Answer Source

Apps targeting Android N do not receive CONNECTIVITY_ACTION broadcasts, even if they have manifest entries to request notification of these events. Apps that are running can still listen for CONNECTIVITY_CHANGE on their main thread if they request notification with a BroadcastReceiver.

To see what changed in Android N. Please refer bellow link. Android N Behaviour Changes

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download