我是android新手,对此我感到震惊,我如何在android中特定时间和日期向用户发送通知,请帮助我。感谢Advamce
您基本上可以使用此示例,您需要通过notificationTime-currentTime计算延迟https://www.tutorialspoint.com/how-to-set-an-android-notification-to-a-specific-date-in-the-future
private void scheduleNotification (Notification notification , long delay)
{
Intent notificationIntent = new Intent( this, MyNotificationPublisher.class);
notificationIntent.putExtra(MyNotificationPublisher. NOTIFICATION_ID , 1 );
notificationIntent.putExtra(MyNotificationPublisher. NOTIFICATION , notification);
PendingIntent pendingIntent = PendingIntent. getBroadcast ( this, 0, notificationIntent, PendingIntent. FLAG_UPDATE_CURRENT);
AlarmManager alarmManager = (AlarmManager) getSystemService(Context. ALARM_SERVICE);
assert alarmManager != null;
alarmManager.set(AlarmManager. ELAPSED_REALTIME_WAKEUP , delay , pendingIntent) ;
}
如果您需要在特定时间间隔重复通知,则可以使用警报管理器https://developer.android.com/reference/android/app/AlarmManager
您应尽量避免使用警报管理器,而应使用Android的新架构组件(即工作管理器)。使用此链接可帮助您安排功能。https://medium.com/androiddevelopers/workmanager-periodicity-ff35185ff006