Android Boot_Completed Not Received When Application Is Closed

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 BOOT_COMPLETED not received when application is closed

I start my app when the BOOT_COMPLETED, so I know it's working. I add Log.d it won't show. I add Toast it show. Small differents in Manifest.xml

<receiver android:name="com.example.startuptest.StartUpBootReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>

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");
/**
* .....
**/
}
}

Android 10 BOOT_COMPLETED Broadcast not received to application

try to add add android:directBootAware to your <receiver, as in DOCs



Related Topics



Leave a reply



Submit