Advertisement
Guest User

Untitled

a guest
Sep 21st, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.20 KB | None | 0 0
  1. Date dt = new Date();
  2. SimpleDateFormat sdf = new SimpleDateFormat("hh:mm a");
  3. String time = sdf.format(dt);
  4. String start_time;
  5.  
  6. Calendar sCalendar = Calendar.getInstance();
  7. String dayLongName = sCalendar.getDisplayName(Calendar.DAY_OF_WEEK, Calendar.LONG, Locale.getDefault());
  8.  
  9. DatabaseHelper helper = new DatabaseHelper(getApplicationContext());
  10. SQLiteDatabase sqLiteDatabase = helper.getReadableDatabase();
  11. String checktime = "Select * from SCHEDULE where week_day='"+dayLongName+"'";
  12.  
  13. Cursor cursor = sqLiteDatabase.rawQuery(checktime, null);
  14. if(cursor.moveToNext()) {
  15.  
  16. start_time = cursor.getString(cursor.getColumnIndex(DatabaseHelper.STARTTIME));
  17.  
  18. SimpleDateFormat simpleDateFormat = new SimpleDateFormat("hh:mm a",Locale.getDefault());
  19. SimpleDateFormat simpleDateFormat2 = new SimpleDateFormat("hh:mm",Locale.getDefault());
  20.  
  21. Date milli =simpleDateFormat2.parse(start_time);
  22. String milli2 = simpleDateFormat2.format(milli);
  23.  
  24. Date timeparsed1 = simpleDateFormat.parse(start_time);
  25. String timeparsed2 = simpleDateFormat.format(timeparsed1);
  26.  
  27. String s = milli2;
  28. Pattern p = Pattern.compile("(\d+):(\d+)");
  29. Matcher m = p.matcher(s);
  30.  
  31. if (m.matches()) {
  32. int hrs = Integer.parseInt(m.group(1));
  33. int min = Integer.parseInt(m.group(2));
  34.  
  35. long ms = (long) hrs * 60 * 60 * 1000 + min * 60 * 1000;
  36. // System.out.println("hrs=" + hrs + " min=" + min + " ms=" + ms);
  37.  
  38. Intent intent = new Intent(this, MyBroadcastReceiver.class);
  39.  
  40. PendingIntent pendingIntent = PendingIntent.getBroadcast(this.getApplicationContext(), 234324243, intent, 0);
  41.  
  42. AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
  43.  
  44. alarmManager.set(AlarmManager.RTC_WAKEUP, ms , pendingIntent);
  45.  
  46. //Toast.makeText(getApplicationContext(),String.valueOf(ms),Toast.LENGTH_SHORT).show();
  47.  
  48. } else {
  49.  
  50. Toast.makeText(getApplicationContext(),"Bad Format",Toast.LENGTH_SHORT).show();
  51.  
  52. }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement