Hello there
I wan't to statically register a Broadcast Receiver and I have followed the guidelines at
https://docs.microsoft.com/en-us/xamarin/android/app-fundamentals/broadcast-receivers
As I understand we do not register the Broadcast Receiver directly in the Android Manifest file, but instead we decorate our receiver as following
[BroadcastReceiver(Enabled = true)]
[IntentFilter(new[] { "com.xamarin.example.TEST" })]
public class MySampleBroadcastReceiver : BroadcastReceiver
{
public override void OnReceive(Context context, Intent intent)
{
Console.WriteLine("Hurray it works"!);
}
}
Then the receiver should be able to pick up on the following broadcast
Intent message = new Intent("com.xamarin.example.TEST");
SendBroadcast(message);
However I do not receive this intent. I only receive the intent, when I register the receiver within the context as following
RegisterReceiver(new MySampleBroadcastReceiver(), new IntentFilter("com.xamarin.example.TEST"));
Have I misunderstood something or am I missing some steps? Any help would be appreciated.
Why do I need this?
My goal is to launch notifications at particular timestamps defined by the user. I've context-registered a broadcast receiver, that issues a notification, when an intent is received. The Android Alarm Manager is used to broadcast the intent at a particular time.
As the broadcast receiver is context-registered it will not receive intents, when the app has been killed (when the app is swiped in the recent applications menu). I want the notifications to keep coming when the app has been swiped.