Broadcastreceiver Not Receiving Boot_Completed

BroadcastReceiver not receiving BOOT_COMPLETED

Turns out the receiver wasn't in the tag of the manifest. Whoops! Thanks for your help guys! The worst part about testing this is having to keep turning off and on the phone. :P

Android BroadcastReceiver not receiving BOOT_COMPLETED event

Remove android:exported="false" from the <receiver> element. As it stands, it cannot receive broadcasts from outside of the app.

Also, you have a typo in the <action> element. It should be <action android:name="android.intent.action.BOOT_COMPLETED" />.

And, finally, replace context.startActivity(i); with context.startService(i);, as you are trying to start a service, not an activity.

Android boot completed notification not received after reboot

There are some suggestions online that except the BOOT_COMPLETED action you also need the QUICKBOOT_POWERON that is supported by some devices.
You can check this Q/A for details.

Trying to implement this I also had to add the android:enabled="false" and then on demand when the user select it I programmatically changed this to android:enabled="true" but this a bit more complicated to try.

You can start by changing your code with this to see if it works.

<receiver android:name=".BootCompletedReceiver" 
android:enabled="true">
<intent-filter>
<action android:name="android.intent.action.QUICKBOOT_POWERON" />
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>

In case you like to try the disable logic and then enable this programmatically to do it use this code:

private static void changeBootStateReceiver(Context context, boolean enable) {
ComponentName receiver = new ComponentName(context, BootCompletedReceiver.class);
PackageManager pm = context.getPackageManager();

pm.setComponentEnabledSetting(receiver,
enable ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED
: PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
PackageManager.DONT_KILL_APP);
}

I also like to disable the feature when I no longer need it.

Special cases:

Depending on device manufacturer there are some reports for different broadcasts upon boot:

  • Xiaomi MIUI use: android.intent.action.REBOOT
  • HTC use: com.htc.action.QUICKBOOT_POWERON

Android: BroadcastReceiver won't listen to BOOT_COMPLETED

There might be restriction with setting up several intent-filer action. So change you defining to the next.

<!-- Don't forget about permission -->
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>


<!-- ... -->
<receiver android:name=".helpers.notification.AlarmRebootReceiver"
android:permission="android.permission.RECEIVE_BOOT_COMPLETED">

<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
</intent-filter>
</receiver>

For all other intent filters use separate Receiver. Now you could receive events in the your method. Just print logs, to ensure the even is coming. And few devices to check it's not a device specific.

public class AlarmRebootReceiver extends BroadcastReceiver {

@Override
public void onReceive(Context oContext, Intent intent) {
Log.d("", "Event Received");
/**
* .....
**/
}
}

My BroadcastReceiver is not receiving the BOOT_COMPLETED intent after my N1 boots

All the applications that receive the BOOT_COMPLETED broadcast must be installed on the internal storage because Android delivers ACTION_BOOT_COMPLETED broadcast before the external storage is mounted to the device.

To ensure that your application will be installed on the internal memory you just need NOT to declare the android:installLocation manifest attribute.

Another option is to set the following in the manifest section: android:installLocation="internalOnly"

You can find more information about it here.

BOOT_COMPLETED not working Android

This below thing worked for me

AndroidManifest.xml

<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />

<application>

<receiver android:name=".BootCompletedReceiver" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.QUICKBOOT_POWERON" />
</intent-filter>
</receiver>

<service android:name="NotifyingDailyService" >
</service>

BootCompletedReceiver.class

public class BootCompletedReceiver extends BroadcastReceiver {

@Override
public void onReceive(Context context, Intent arg1) {
// TODO Auto-generated method stub
Log.w("boot_broadcast_poc", "starting service...");
context.startService(new Intent(context, NotifyingDailyService.class));
}

}

Service.class

 public class NotifyingDailyService extends Service {

@Override
public IBinder onBind(Intent arg0) {
// TODO Auto-generated method stub
return null;
}

@Override
public int onStartCommand(Intent pIntent, int flags, int startId) {
// TODO Auto-generated method stub
Toast.makeText(this, "NotifyingDailyService", Toast.LENGTH_LONG).show();
Log.i("com.example.bootbroadcastpoc","NotifyingDailyService");

return super.onStartCommand(pIntent, flags, startId);
}
}

Android 8.0 - BroadcastReceiver not receiving after a reboot

Starting from Android O, you can not start a service from a background app without getting an exception:

java.lang.IllegalStateException: Not allowed to start service Intent
(my_service) : app is in background

If you still need to launch a service at device start up, you can now use the new JobIntentService.

Change your IntentService to a JobIntentService:

public class ReactivationService extends JobIntentService {

public static final int JOB_ID = 0x01;

public static void enqueueWork(Context context, Intent work) {
enqueueWork(context, ReactivationService.class, JOB_ID, work);
}

@Override
protected void onHandleWork(@NonNull Intent intent) {
// do your stuff here
}

}

Use it as follow in your StartupReceiver:

public class StartupReceiver extends BroadcastReceiver {

@Override
public void onReceive(Context context, Intent intent) {
if (Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())) {
ReactivationService.enqueueWork(context, new Intent());
}
}

}

Declare your service inside the manifest:

<service android:name=".ReactivationService"
android:permission="android.permission.BIND_JOB_SERVICE"/>

And that’s it. This will either directly start the service (when running on pre-O platforms) or enqueue work for it as a job (when running on O and later). No matter what the platform is, everything you pass in enqueueWork will ultimately appears in onHandleWork.



Related Topics



Leave a reply



Submit