0
我有一個數據庫設置了3列,ID,TASK和TIME。時間從Timepicker放置在數據庫中。我需要弄清楚如何讀取數據庫中的時間值,然後根據這些時間設置鬧鐘,任何想法?基於Android的數據庫值/時間設置鬧鐘?
我的按鈕有以下代碼來設置報警並將值添加到數據庫中。
final EditText edt = (EditText) dialogView.findViewById(R.id.edit1);
tp = (TimePicker) dialogView.findViewById(R.id.timePicker);
String task = edt.getText().toString(); //retrieve vales from fields
String strDateTime = tp.getCurrentHour() + ":" + tp.getCurrentMinute();
int minutes = tp.getCurrentMinute();
int hourr = tp.getCurrentHour();
Intent alarmIntent = new Intent(Meds2.this, AlarmReceiver.class);
pendingIntent = PendingIntent.getBroadcast(Meds2.this, 0, alarmIntent, 0);
AlarmManager manager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
int interval = 1000 * 60 * 20;
/* Set the alarm to start at 10:30 AM */
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(System.currentTimeMillis());
calendar.set(Calendar.HOUR_OF_DAY, hourr);
calendar.set(Calendar.MINUTE, minutes);
Log.e(TAG, "Time is set at: " + calendar.getTime());
/* Repeating on every 20 minutes interval */
manager.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(),
1000 * 60 * 20, pendingIntent);
TaskDBHelper helper = new TaskDBHelper(Meds2.this);
SQLiteDatabase sqlDB = helper.getWritableDatabase();
ContentValues values = new ContentValues();
values.clear();
values.put(TaskContract.Columns.TASK, task); //place values in db
values.put(TaskContract.Columns.DATE, strDateTime);
sqlDB.insertWithOnConflict(TaskContract.TABLE, null, values,
SQLiteDatabase.CONFLICT_IGNORE);
我報警接收機類有以下幾點:
@Override
public void onReceive(Context context, Intent intent)
{
NotificationCompat.Builder builder =
new NotificationCompat.Builder(context)
.setSmallIcon(R.drawable.ic_cast_light)
.setContentTitle("Please Take Your Meds")
.setContentInfo("Time")
.setContentText("Enjoy")
.setDefaults(Notification.DEFAULT_SOUND)
.setAutoCancel(true)
.setVibrate(new long[]{1000, 1000, 1000, 1000}) //set virbrate & color of led
.setLights(Color.BLUE, 3000, 3000);
int NOTIFICATION_ID = 12345;
NotificationManager nManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
nManager.notify(NOTIFICATION_ID, builder.build());
}
因此我需要弄清楚(在您的幫助:)) 如何設置多個鬧鐘 如何把它們發給基礎上,數據庫值 我需要它們每天重複同時進行。 setRepeating我認爲。
由於您在1.5小時內沒有得到答案,因此不會回答問題。 – Soana