HiB HiB - 1 year ago 245
Android Question

broadcasting of BOOT_COMPLETED intent action does not work properly

I have a receiver class listening on several actions but it can not catch the

action. What I am doing wrong? here is my manifest file:

<uses-sdk android:minSdkVersion="7" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<!--<receiver android:name=".OtherReceiver">
<action android:name="android.intent.action.BOOT_COMPLETED" />
<receiver android:name="com.myApp.AppReceiver" android:permission="android.permission.RECEIVE_BOOT_COMPLETED">
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.PACKAGE_ADDED"/>
<action android:name="com.myApp.wifitimer"/>
<action android:name="android.intent.action.PACKAGE_REPLACED" />
<data android:scheme="package" android:path="com.myApp" />

as it can be seen I added the permission again inside the receiver and the name of the receiver gets the full name of the class as this answer suggests.

here is the broadcast receiver class:

public void onReceive(Context arg0, Intent arg1) {

String action1 = arg1.getAction();

if(action1.equals(Intent.ACTION_BOOT_COMPLETED)) {
Log.d("receiver","action is: boot");
if(action1.equals("android.intent.action.PACKAGE_REPLACED")) {
Log.d("receiver","action is: package");

When I run the app the receiver catches the
but when I restart the phone the receiver does not catch the

However when I comment in the
in the Mainfest file it can catch it!

here is the code of this class:

public class OtherReceiver extends BroadcastReceiver {

public void onReceive(Context arg0, Intent arg1) {

String action = arg1.getAction();

if(action.equals(Intent.ACTION_BOOT_COMPLETED)) {
Log.d("new receiver","action is: boot");


just the same as the other one. So my question is why I need define a separate receiver for the

Edit: I also tried to send the action via adb according to this, and without any permission I could catch it with the AppReceiver class:

am broadcast -a android.intent.action.BOOT_COMPLETED -c android.intent.category.HOME -n com.blubuk/.AppReciever

Answer Source

First, remove android:permission="android.permission.RECEIVE_BOOT_COMPLETED" from your <receiver> element.

Second, your <data> portion of your <intent-filter> is applying to all <action> elements within that <intent-filter>, which you do not want. There is no Uri on ACTION_BOOT_COMPLETED.

However, rather than creating a separate <receiver> element, you could just create a separate <intent-filter> element on your original <receiver> element. Move your <action android:name="android.intent.action.BOOT_COMPLETED" /> to the new <intent-filter> (and perhaps that com.myApp.wifitimer one too), so that they are unaffected by the <data> of your first <intent-filter>.

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