I have a value in my database with this Time format "10:40 AM" now I'm going to use it to the Alarm Manager this is my alarm manager code.
Long alertTimeCatcher = new GregorianCalendar().getTimeInMillis()+10*1000;
+10*1000
I want to change the 10 inside to the double quote with my "10:40 AM" so I'm going to convert it into integer. How am I going to do this?
Let just say I have "11:40 AM" I will convert it into integer
int Time = "11:40 AM";
This is the original code then
Long alertTimeCatcher = new GregorianCalendar().getTimeInMillis()+10*1000;
Then this is what I need
Long alertTimeCatcher = new GregorianCalendar().getTimeInMillis()+Time*1000;
So in order to trigger my alarm manager I need to convert my time into integer.
This is what I've tried so far.
try {
Cursor c = myDB.rawQuery("SELECT * FROM " + "tblEvents", null);
int Column2 = c.getColumnIndex("Date");
int Column3 = c.getColumnIndex("Time");
String[] arr = new String[0];
// Check if our result was valid.
ArrayList<String> list = new ArrayList<String>();
c.moveToFirst();
if (c != null) {
// Loop through all Results
do {
String Date = c.getString(Column2);
String Time = c.getString(Column3);
Calendar ca = Calendar.getInstance();
SimpleDateFormat df = new SimpleDateFormat("M/dd/yyyy");
String formattedDate = df.format(ca.getTime());
if (Date.equalsIgnoreCase(formattedDate)) {
list.add(Time);
Toast.makeText(getApplicationContext(), "Converter : ", Toast.LENGTH_SHORT).show();
}
} while (c.moveToNext());
}
Collections.reverse(list);
}catch(CursorIndexOutOfBoundsException e){
e.printStackTrace();
}
Long alertTimeCatcher = new GregorianCalendar().getTimeInMillis()+10*1000;
Toast.makeText(getApplicationContext(),alertTimeCatcher.toString(),Toast.LENGTH_SHORT).show();
Intent alertIntent = new Intent(this,AlertReceiver.class);
AlarmManager alarmManager = (AlarmManager)getSystemService(Context.ALARM_SERVICE);
alarmManager.set(AlarmManager.RTC_WAKEUP,alertTimeCatcher,PendingIntent.getBroadcast(this,1,alertIntent,PendingIntent.FLAG_UPDATE_CURRENT));