Forum Xamarin.Android

Why isn't my BroadcastReceiver for ActionBootCompleted working?

MazenMazen DEMember
edited December 2016 in Xamarin.Android

Hey everyone,

I'm kinda new to Xamarin, in fact this is my first bigger project.
I need a service which is always running, whether or not the app itself is running.

So I figured, I'm trying to receive the ActionBootCompleted Intent and start my service then. But for some reason it's not working at all.
Can someone help me out here?

[BroadcastReceiver(Enabled = true)] [IntentFilter(new[] { Intent.ActionBootCompleted })] class BootReceiver : BroadcastReceiver { public override void OnReceive(Context context, Intent intent) { Toast.MakeText(context, "Boot received! " + intent.Action, ToastLength.Long).Show(); Console.WriteLine("Boot received! " + intent.Action); if(intent.Action != null && intent.Action == Android.Content.Intent.ActionBootCompleted) { context.ApplicationContext.StartService(new Intent(context, typeof(NotificationService))); } } }

I don't get any output. Not the toast, no log, and also nothing from the NotificationService at all.

Added [BroadcastReceiver(Enabled = true, Exported = true, Permission = "RECEIVE_BOOT_COMPLETED")] without success.

Adding <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> didn't help either.

Best Answer


  • ChristopheBERNARDChristopheBERNARD BEMember ✭✭✭✭✭

    Hello @mazenlhm

    normally you must to save your broadcast into the manifest

    did you do that ?

    read perhpas this question

  • MazenMazen DEMember
    edited December 2016

    Aren't the attributes I put before the class meant to do that?

    But now that you mentioned it, I just had a look into the generated AndroidManifest.xml. There I found this:

    <receiver android:enabled="true" android:exported="true" android:permission="RECEIVE_BOOT_COMPLETED" android:name="md502b003a23dd1a56b0700c2aa2eb37a03.BootReceiver"> <intent-filter> <action android:name="android.intent.action.BOOT_COMPLETED" /> <category android:name="android.intent.category.HOME" /> </intent-filter> </receiver>

    "md502b003a23dd1a56b0700c2aa2eb37a03.BootReceiver" doesn't seem correct, or is it?

  • BenHlzemerBenHlzemer USMember ✭✭

    is there A way to speed up the boot receiver.also the docu states that it is strongly discouraged to start activities from the receiver. so whats the right way?

  • GeorgiZGeorgiZ BGMember ✭✭

    Maybe it's too late, but try removing the attribute "Permission" and leave the permission declared only in the AndroidManifest.xml. Check my comment in

Sign In or Register to comment.