I am trying to start a service when my device boots up, but the service never starts.
I have added:
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
to AndroidManifest.xml. My BroadcastReceiver looks like this:
[BroadcastReceiver]
[IntentFilter(new[] { Intent.ActionBootCompleted })]
public class BootReceiver : BroadcastReceiver
{
public override void OnReceive(Context context, Intent intent)
{
var start = new Intent(context, typeof(AlertSyncService));
start.AddFlags(ActivityFlags.NewTask);
context.StartService(start);
}
}
I have confirmed my service is not the issue (tested by starting the same service on button click - it works fine). The issue is definitely that the BroadcastReceiver is never receiving the event. I've also ensured that I open the app once before rebooting - I saw in a similar question that this is necessary, as apps are installed in a "stopped state".
Does anybody have any ideas what could be causing this not to work? I'm relatively new to this, so highly likely I've missed something obvious!
Thanks