AlarmManagerの将来の日付値を作成するために、DatePickerとTimePickerを使用してユーザに提示するアプリケーションを作成しています。TimePickerDialog内のコンテキストの取得
私は、ユーザーがDatePickerでDateを選択したときに表示するTimePickerを連鎖しています。
TimePickerの内部で、ユーザーが時間を選択すると、保留中のインテントを作成して、AlarmManagerを設定します。しかし、インテントを作成しようとすると、コンテキストを取得できないようだからクラッシュする。
私はIntentをDatePicker内に作成すると、それは機能します。
public void onDateSet(DatePicker view, int year, int month, int day) {
mCallback.onDateSelected(year, month, day);
calendar.set(Calendar.YEAR, year);
calendar.set(Calendar.MONTH, month);
calendar.set(Calendar.DAY_OF_MONTH, day);
TimePickerDialog timePickerDialog = new TimePickerDialog(getContext(), this, 1, 1, true);
timePickerDialog.show();
}
/**
* @param view
* @param hourOfDay
* @param minute
*/
@Override
public void onTimeSet(android.widget.TimePicker view, int hourOfDay, int minute) {
mTimeCallback.onTimeSelected(hourOfDay, minute);
calendar.set(Calendar.HOUR_OF_DAY, hourOfDay);
calendar.set(Calendar.MINUTE, minute);
Long millis = calendar.getTimeInMillis();
long futureInMillis = SystemClock.elapsedRealtime() + millis;
Intent notificationIntent = new Intent(getContext(), NotificationPublisher.class);
notificationIntent.putExtra(NotificationPublisher.NOTIFICATION, getNotification());
PendingIntent pendingIntent = PendingIntent.getBroadcast(getContext(), 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager alarmManager = (AlarmManager) getActivity().getSystemService(Context.ALARM_SERVICE);
alarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, 100, pendingIntent);
Log.i("Got here", "yes");
}