https://xamarinhelp.com/xamarin-background-tasks/#comment-1296 .. am using this background worker. I want to show Local Notification Repeatedly on every day where my application state either running or not. Its not work for me.. Please help. SendNotification() is calling from main activity. The repeated Local notification is worked well where my application state is running. But its not worked where my application state is not running.
public async Task SendNotification()
{
Intent alarmIntent = new Intent(this, typeof(AlarmReceiverNew));
alarmIntent.PutExtra(“message”, “message”);
alarmIntent.PutExtra(“title”, “Welcome”);
PendingIntent pendingIntent = PendingIntent.GetBroadcast(this, 0, alarmIntent, PendingIntentFlags.UpdateCurrent);
AlarmManager alarmManager = (AlarmManager)this.GetSystemService(Context.AlarmService);
long futureInMillis = SystemClock.ElapsedRealtime() + 12 * 3600 * 1000;
alarmManager.Set(AlarmType.ElapsedRealtimeWakeup, futureInMillis, pendingIntent);
}
[BroadcastReceiver]
public class AlarmReceiverNew : BroadcastReceiver
{
public async override void OnReceive(Context context, Intent intent)
{
Intent notIntent = new Intent(context, typeof(MainActivity));
PendingIntent contentIntent = PendingIntent.GetActivity(context, 0, notIntent, PendingIntentFlags.CancelCurrent);
NotificationManagerCompat manager = NotificationManagerCompat.From(context);
var wearableExtender = new NotificationCompat.WearableExtender().SetBackground(BitmapFactory.DecodeResource(context.Resources, 1));
NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
.SetContentIntent(contentIntent)
.SetSmallIcon(Resource.Drawable.icon).SetContentTitle(“title”)
.SetContentText(“message”)
.SetWhen(Java.Lang.JavaSystem.CurrentTimeMillis())
.SetSound(RingtoneManager.GetDefaultUri(RingtoneType.Notification))
.Extend(wearableExtender);
Notification notification = builder.Build();
manager.Notify(0, notification);
}
}
am trying Android - Running a background task every 15 minutes, even when application is not running solution also. but output where same.