I have a database set up with 3 Columns, ID, TASK and TIME. The time is placed in the DB from a Timepicker. I need to figure out how to read the Time values in the database then set the alarm based of these times, any ideas?
My button has the following code to set Alarm and add values into db.
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);
My Alarm Receiver Class has the following:
@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());
}
Therefore I need to figure out(with your help:)) How to set multiple Alarms How to then set them based on the Database values I need them to repeat everyday at the same time. setRepeating I think.
Aucun commentaire:
Enregistrer un commentaire