Search code examples
android-broadcastandroid

Static receiver not running


I created an application that consists of one static receiver:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.docd.connectivityresetter"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="15"
        android:targetSdkVersion="19" />

    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />

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

        <receiver android:name=".ConnectivityReceiver"
            android:enabled="true">
            <intent-filter>
                <action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
            </intent-filter>
        </receiver>

    </application>

</manifest>

The receiver

package com.docd.connectivityresetter;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

public final class ConnectivityReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(final Context context, final Intent intent) {
        android.util.Log.i("received", intent.getAction());
        android.util.Log.i("received", intent.getExtras().toString());
    }

}

Installed the application.

1) Nothing received (no logs) when I trigger Airplane Mode (cell network goes down)

2) My application is not listed in "Running" tab of phone's Application settings menu (shouldn't it be listed as "Running" when static receiver is registered)?

I came across this when searching. Everything matches except it doesn't work for me. Intent action for network events in android sdk


Solution

  • Finally I found this great answer when I couldn't receive BOOT_COMPLETED either.

    BroadcastReceiver not receiving BOOT_COMPLETED

    I would have never known...