几天前我开始开发android。我的应用程序需要每天早上和晚上发送通知。如果应用程序在前台,如果它在后台通知只是不显示,它就可以工作。
private void BackgroundWorker_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
if (e.ProgressPercentage == 2)
{
GenerateMorningNotification();
}
else if (e.ProgressPercentage == 3)
{
GenerateEveningNotification();
}
}
我使用后台工作程序,在进度更改事件中我使用一种生成通知的方法,例如:
private void GenerisiJutarnjuNotifikaciju()
{
Notification.Builder builder = new Notification.Builder(this)
.SetContentTitle("Dobro jutro")
.SetStyle(new Notification.BigTextStyle().BigText(poruke.RandomPoruka()))
.SetSmallIcon(Resource.Drawable.Icon);
Notification notification = builder.Build();
NotificationManager notificationManager = GetSystemService(Context.NotificationService) as NotificationManager;
const int notificationId = 0;
notificationManager.Notify(notificationId, notification);
}
关于我应该更改什么的任何建议?我正在为我女朋友的生日开发这个应用程序,所以我有点赶时间。如果有人可以提供帮助,我将不胜感激。谢谢。
最佳答案
我认为使用 AlarmManager
设置一个 Alarm
来触发一个 BroadcastReceiver
通常是当你希望某事在某个特定时间发生时使用的时间,即使应用程序不在前台。
这里的代码非常详细地说明了这是如何完成的:Send notification once in a week
关于c# - 应用程序在后台时不显示通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41309122/