Registering for Broadcast through AndroidManifest

Here is a small tip that took me a while to figure out but hopefully will save someone time and frustration. I have a BroadcastReceiver in my application that listens for network connectivity changes so the app. can resume background work on network availability.

If you register for receiver in AndroidManifest.xml then you need to write the actual constant value inside the <intent-filter> tag:

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

The value is for the intent constant ConnectivityManager.CONNECTIVITY_ACTION. There are no warning or exceptions if you put this constant variable straight away in AndroidManifest.xml but the receiver won’t catch the network change events so a little hard to debug.

Note that if you register for a broadcast receiver from within code then just referring to the constant will work fine.

Advertisements

One thought on “Registering for Broadcast through AndroidManifest

  1. Pingback: Android BroadcastReceiver can’t receive any broadcast events | Android Development tutorial | Android Development tutorial

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s