Android xamarin指定月、日本地通知



一段时间以来,他一直试图在应用程序中为给定的日期和月份设置通知。不幸的是,每天调用它几秒钟后,通知就会出现。

这是我的代码:

private void Remind_Click(object sender, System.EventArgs e)
{
string title = "If you see this";
string message = "it means it works";
Intent alarmIntent = new Intent(Application.Context, typeof(AlarmReceiver));
alarmIntent.PutExtra("message", message);
alarmIntent.PutExtra("title", title);
var pendingIntent = PendingIntent.GetBroadcast(this, 0, alarmIntent, PendingIntentFlags.UpdateCurrent);
var alarmManager = GetSystemService(AlarmService).JavaCast<AlarmManager>();
DateTime nowDate = DateTime.Now;
int month = 09;
int day = 24;
DateTime newDate = new DateTime(nowDate.Year, month, day);                   
DateTime date = newDate;
var ms = (long)(date - new DateTime(1970, 1, 1)).TotalMilliseconds;
alarmManager.SetInexactRepeating(AlarmType.RtcWakeup, 3600000, ms, pendingIntent);
ShowSnack(main, $"Set date: {date} ");
}

请帮我解决这个问题。

  1. 对于setInexactRepeating (int type, long startTime, long intervalTime, PendingIntent pi);,第二个参数为开始执行时间,第三个参数为两次执行之间的间隔时间。所以你在输入参数时出现了错误。
  2. 如果您只触发一次事件,您可以使用set(int type, long startTime, PendingIntent pi);。使用此方法将只触发一次事件。

注意:因为您使用的是alarmtype . rtcwake。DateTime的时间。现在可能不同于Utc时间(您可以使用DateTime。Now和DateTime。(查看两者之间是否有时差)。

最新更新