我需要生成一个随机日期(小时+分钟)来触发随机通知。什么是最好的方法?构建 2 个随机数(从 0 到 23 小时,从 0 到 59 分钟)并将它们放入变量中?
Random generator = new Random();
int b = 23
int random = generator.nextInt(b);
boolean flag = generator.nextBoolean();
x=random;
开始通知:
Calendar cal1 = Calendar.getInstance();
cal1.set(Calendar.HOUR_OF_DAY, 05);
cal1.set(Calendar.MINUTE, 00);
Intent intent2 = new Intent(context, Random.class);
PendingIntent random = PendingIntent.getBroadcast(context, 0, intent2, 0);
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, cal1.getTimeInMillis(), DateUtils.DAY_IN_MILLIS, random);