I'm tryingto create an application in which I need to send the user notifications when the app isn't running. I'm doing it with a broadcast reciever which starts working when the date changes. Meaning when the date changes the broadcast reciever uses a handler in order to send a notification. when the app is running it works perfectly however when the app isn't running the broadcast reciever doesn't work and the notfication isn't sent.
here is the code:
first in the manifest I have:
<receiver android:name=".MyBroadcastRecieverDate" >
<intent-filter>
<action android:name="android.intent.action.DATE_CHANGED" />
</intent-filter>
</receiver>
in Main activity i build and register the broadcast reciever:
this.recieverDate = new MyBroadcastRecieverDate();
protected override void OnResume()
{
base.OnResume();
RegisterReceiver(recieverDate, new IntentFilter(Intent.ActionDateChanged));
}
and this is the reciever's class:
[BroadcastReceiver(Enabled = true)]
[IntentFilter(new[] { Intent.ActionDateChanged })]
class MyBroadcastRecieverDate : BroadcastReceiver
{
MyHandler handler;
public MyBroadcastRecieverDate()
{
}
public override void OnReceive(Context context, Intent intent)
{
if(intent.Action.Equals(Intent.ActionDateChanged))
{
handler = new MyHandler(context);
Message msg = new Message();
msg.Obj = "";
msg.Arg1=1;
handler.SendMessage(msg);
}
}
}
If someone can please help me and tell me how to make the reciever work even when the app isn't running it will help me a lot. Thank you.