I have a worker which functions perfectly. I want to launch it when the phone is booted. I use a broadcast receiver which is supposed to listen to the system booted_completed event, but this broadcast receiver is never called.
In my manifest, I added this permission: <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
Here is my broadcast receiver:
[BroadcastReceiver(Enabled = true)]
[IntentFilter(new[] { Android.Content.Intent.ActionBootCompleted })]
public class BootBroadcastReceiver : BroadcastReceiver
{
public override void OnReceive(Context context, Intent intent)
{
//Notify that the broadcast receiver is launched
await AndroidNotificationService.NotifyUser("Device boot", "The device is booting", 11, context);
OneTimeWorkRequest notifWork = new OneTimeWorkRequest.Builder(typeof(Services.Background.NotificationsBackgroundWorker))
.Build();
WorkManager.Instance.Enqueue(notifWork);
}
}
But this dosn't help. the receiver never starts when I reboot my device. I'm testing this on android 9.