I have a receiver class that listens for several actions, but it cannot catch the android.intent.action.BOOT_COMPLETED action. What am I doing wrong? here is my manifest file:
<uses-sdk android:minSdkVersion="7" /> <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> <receiver android:name="com.myApp.AppReceiver" android:permission="android.permission.RECEIVE_BOOT_COMPLETED"> <intent-filter> <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" /> </intent-filter> </receiver>
as you can see, I again added permission inside the recipient, and the recipient name gets the fully qualified class name, as suggested.
here is the broadcast receiver class:
@Override 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 launch the application, the receiver catches android.intent.action.PACKAGE_REPLACED , but when I restart the phone, the receiver will not catch BOOT_COMPLETED .
However, when I comment on the .OtherReceiver file in the .OtherReceiver file, it can catch it!
here is the code of this class:
public class OtherReceiver extends BroadcastReceiver { @Override 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 like the other. So my question is why do I need to define a separate receiver for the BOOT_COMPLETED action?
Edit: I also tried sending the action via adb in accordance with this , and without any permissions 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