0
我需要隨機生成一個日期(小時+分鐘)來觸發隨機通知。什麼是最好的方法?建立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);