public override void OnReceive(Context context, Intent intent) { System.Diagnostics.Debug.WriteLine("Alarm {0} {1}", DateTime.Now, "ups"); //Every time the `RepeatingAlarm` is fired, set the next alarm //Intent intent = new Intent(context, typeof(RepeatingAlarm)); PendingIntent source = PendingIntent.GetBroadcast(context, 0, intent, 0); AlarmManager am = (AlarmManager)context.GetSystemService(Context.AlarmService); LsMqtt mqtt = App.Web.GetLastState("Gustav"); if (mqtt != null) { mqtt.Dat.Firmware = "1.23"; App.History.Add(new HistoryItem(DateTime.Now, mqtt)); //Context context = Android.App.Application.Context; //AlarmManager am = (AlarmManager)context.GetSystemService(Context.AlarmService); NotificationManager nm = (NotificationManager)context.GetSystemService(Context.NotificationService); if (App.NotifyMsg(mqtt.Dat)) { var notIntent = new Intent(context, typeof(MainActivity)); var contentIntent = PendingIntent.GetActivity(context, 0, notIntent, PendingIntentFlags.CancelCurrent); var builder = new NotificationCompat.Builder(context, MainActivity.cn) .SetAutoCancel(true) // Dismiss the notification from the notification area when the user clicks on it .SetContentIntent(contentIntent) // Start up this activity when the user clicks the intent. .SetContentTitle("Notify") // Set the title //.SetNumber(count) // Display the count in the Content Info .SetSmallIcon(Resource.Drawable.Icon_Notify) // This is the icon to display .SetContentText(mqtt.Dat.State.ToString()); // the message to display. nm.Notify(1000, builder.Build()); } } am.SetAndAllowWhileIdle(AlarmType.ElapsedRealtimeWakeup, SystemClock.ElapsedRealtime() + 5 * 60 * 1000, source); //Toast.MakeText(context, "repeating_received and after 15s another alarm will be fired", ToastLength.Short).Show(); }
public bool Start() { Context context = Android.App.Application.Context; AlarmManager am = (AlarmManager)context.GetSystemService(Context.AlarmService); NotificationManager nm = (NotificationManager)context.GetSystemService(Context.NotificationService); _penint = PendingIntent.GetBroadcast(context, 0, new Intent(context, typeof(RepeatingAlarm)), 0); am.SetAndAllowWhileIdle(AlarmType.ElapsedRealtimeWakeup, SystemClock.ElapsedRealtime() + 3 * 60 * 1000, _penint); var notIntent = new Intent(context, typeof(MainActivity)); var contentIntent = PendingIntent.GetActivity(context, 0, notIntent, PendingIntentFlags.CancelCurrent); //// Build the notification: //var builderOld = new Notification.Builder(context, MainActivity.cn) // .SetAutoCancel(true) // Dismiss the notification from the notification area when the user clicks on it // .SetContentIntent(contentIntent) // Start up this activity when the user clicks the intent. // .SetContentTitle("title") // Set the title // //.SetNumber(count) // Display the count in the Content Info // .SetSmallIcon(Resource.Drawable.Icon_Notify) // This is the icon to display // .SetContentText("message start"); // the message to display. // // Finally, publish the notification: //nm.Notify(1000, builderOld.Build()); // Build the notification: var builder = new NotificationCompat.Builder(context, MainActivity.cn) .SetAutoCancel(true) // Dismiss the notification from the notification area when the user clicks on it .SetContentIntent(contentIntent) // Start up this activity when the user clicks the intent. .SetContentTitle("Title") // Set the title //.SetNumber(count) // Display the count in the Content Info .SetSmallIcon(Resource.Drawable.Icon_Notify) // This is the icon to display .SetContentText($"Notificatin start"); // the message to display. // Finally, publish the notification: nm.Notify(1000, builder.Build()); return(true); }