我在 Android 应用程序中有一个选项可以设置两个通知。基本上,当用户单击按钮时,将显示一个时间选择器,在第一次选择器完成后,将弹出第二个时间选择器供用户第二次插入。
两个时间选择器都在不同的方法中,在第一种方法结束时显示吐司,与第二种方法相同。问题是当第一次选择器完成时,两条吐司消息立即触发,然后当用户第二次完成选择器时,第二条吐司消息再次触发。我已经包含了下面的代码。
/**
* Method which sets the first daily notification
*/
private void startTwiceDailyNotification(Calendar c) {
DialogFragment timePicker = new TimePickerFragment();
AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
Intent intent = new Intent(this, AlertReceiver.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 1, intent, 0);
alarmManager.setExact(AlarmManager.RTC_WAKEUP, c.getTimeInMillis(), pendingIntent);
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, c.getTimeInMillis(), AlarmManager.INTERVAL_DAY, pendingIntent);
Toast.makeText(this, "First Notification Set.", Toast.LENGTH_SHORT).show();
timePicker.show(getSupportFragmentManager(), "time picker4");
hasSelected = 2;
}
/**
* Method which sets the second daily notification
*/
private void startTwiceDailyNotification2(Calendar c) {
AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
Intent intent = new Intent(this, AlertReceiver.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 2, intent, 0);
alarmManager.setExact(AlarmManager.RTC_WAKEUP, c.getTimeInMillis(), pendingIntent);
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, c.getTimeInMillis(), AlarmManager.INTERVAL_DAY, pendingIntent);
Toast.makeText(this, "Second Notification Set.", Toast.LENGTH_SHORT).show();
}
白板的微信
DIEA
扬帆大鱼
相关分类