Code Tutorial: BroadcastReceiver

An updated version is available here.

Let´s start with my first code-tutorial. It´s about BroadcastReceivers:

You can find a code-example in the SayMyName sourcecode.

It´s not very hard to code: implement the method "onReceive" and do what you want to do, when you receive an broadcast.

To make this work right, you have to modify your AndroidManifest.xml:
Write between the application-tag something like:
<receiver android:name=".CallReceiver">
                        <intent-filter>
                                <action android:name="android.intent.action.BOOT_COMPLETED" />
                                <action android:name="android.intent.action.USER_PRESENT" />
                        </intent-filter>
                </receiver>

"android:name" sets the class, which is your broadcastreceiver.
With the "intent-filter"-tag you can control which broadcasts will get forwarded to your receiver.

With this example, your receiver gets the broadcasts "BOOT_COMPLETED" (which needs an additional in the AndroidManifest.xml) and "USER_PRESENT" (which gets sent when you unlock your phone by pressing the Menu-key).

A very tiny list of available broadcasts can be found in the Android API (search for "Standard Broadcast Actions")

That´s it :)
If you have questions, ideas, feedback or whatever, feel free to contact me!

Tom