BOOT_COMPLETED intent action translation is not working properly

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=".OtherReceiver"> <intent-filter> <action android:name="android.intent.action.BOOT_COMPLETED" /> </intent-filter> </receiver>--> <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 
+4
source share
2 answers

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

Secondly, your <data> your <intent-filter> applies to all <action> elements inside the <intent-filter> that you don't need. There ACTION_BOOT_COMPLETED no Uri on ACTION_BOOT_COMPLETED .

However, instead of creating a separate <receiver> element, you can simply create a separate <intent-filter> element in the original <receiver> element. Move <action android:name="android.intent.action.BOOT_COMPLETED" /> to the new <intent-filter> (and perhaps this com.myApp.wifitimer one) so that they do not suffer from the <data> your first <intent-filter> .

+9
source

Replace your manifest with this, and I'm sure it will work. Android Location: Permission in the recipient tag was incorrect.

  <receiver android:name="com.myApp.AppReceiver" android:enabled="true" android:exported="false"> <intent-filter> <action android:name="android.intent.action.BOOT_COMPLETED" /> </intent-filter> </receiver> 
+2
source

All Articles