我想根據他的要求從timepicker接收用戶的輸入,然後我想在此時顯示敬酒信息。我嘗試以下,但它不工作..如何在特定時間設置鬧鐘以顯示敬酒
for (int i = 0; i < mNameList.size(); i++) {
Log.i("mName is ", ""
+ mNameList.get(i).getText().toString());
Log.i("Time is ", "" + timeList.get(i).getText().toString());
String[] time = timeList.get(i).getText().toString()
.split(":");
int hour = Integer.parseInt(time[0]);
int min = Integer.parseInt(time[1]);
Log.i("Hour", "" + hour);
Log.i("Min", "" + min);
Intent intent = new Intent(MainActivity.this,
AlarmReciever.class);
PendingIntent alarmIntent = PendingIntent.getBroadcast(
MainActivity.this, 0, intent,
PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager aManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
Calendar firingcal = Calendar.getInstance();
Calendar currentcal = Calendar.getInstance();
firingcal.set(Calendar.HOUR, hour);
firingcal.set(Calendar.MINUTE, min);
long intendedTime = firingcal.getTimeInMillis();
long currentTime = currentcal.getTimeInMillis();
if (intendedTime >= currentTime) {
aManager.setRepeating(AlarmManager.RTC_WAKEUP,
intendedTime, AlarmManager.INTERVAL_DAY,
alarmIntent);
} else {
firingcal.add(Calendar.DAY_OF_MONTH, 1);
intendedTime = firingcal.getTimeInMillis();
aManager.setRepeating(AlarmManager.RTC_WAKEUP,
intendedTime, AlarmManager.INTERVAL_DAY,
alarmIntent);
}
}
和我reciever是: -
public void onReceive(Context context, Intent intent) {
Toast.makeText(context, "Hey its Your turn", Toast.LENGTH_LONG).show();
}
,我在manifest.so提到了我的接收器名稱如何在特定的時間顯示敬酒。
嘗試調試它,並檢查intendedtime和currentTime的價值觀 –
intendedtime和CURRENTTIME是確定它們是正確的。 – Harish