Saturday 15 May 2010

android - How can I test timed Notification? Or is my code somehow wrong? -


I want to distribute timed notifications (everyday, 5:00 AM), and this is the alarm code Tries to use:

  Intent to appIntent = new intent (this, NotificationService.class); AlarmManager AlarmManager = (AlarmManager) getSystemService (ALARM_SERVICE); Pending Internet Penientent = Pending.text (this, 0, appointe, 0); AlarmManager.cancel (penIntent); Calendar cal = calendar.justinstance (); Cal.set (calendar.HOUR_OF_DAY, 5); Cal.set (calendar.min, 00); Cal.set (calendar. SECOND, 00); AlarmManager.Settering (alarmman.rtc, cal.getTimeInMillis (), alarmManager.INVAL_DAY, Penentent);   

NotificationService.class looks like this (least important part):

  int id = 001; Information Manager mNotifyMng = (Notification Manager) getSystemService (NOTIFICATION_SERVICE); NotificationCompat.Builder mBuilder = New Notification Builder (main activity.) .setSmallIcon (R.drawable.icon) .setContentTitle ("Test") .setContentText ("Test!"); MNotifyMng.notify (id, mbuilder.build ()); StopSelf ();   

I can not seem to do this work. When I set the emulator clock to 4:59 or something else and wait to change at 5:00, no information is seen and I have no other way to test it. I hope you know a way to check it or find a bug in my code.

I believe the problem is that you cancel pending , But then you have to recreate it before setting it to alarmManager .

  // Pending pending AlarmManager AlarmManager = (AlarmManager) getSystemService (ALARM_SERVICE); Pending Internet Penientent = Pending.text (this, 0, appointe, 0); AlarmManager.cancel (penIntent); // Repeated pending attendant app entity = new intent (this, NotificationService.class); AlarmManager AlarmManager = (AlarmManager) getSystemService (ALARM_SERVICE); Pending Internet Penientent = Pending.text (this, 0, appointe, 0); Calendar cal = calendar.justinstance (); Cal.set (calendar.HOUR_OF_DAY, 5); Cal.set (calendar.min, 00); Cal.set (calendar. SECOND, 00); AlarmManager.Settering (alarmman.rtc, cal.getTimeInMillis (), alarmManager.INVAL_DAY, Penentent); To cancel   

pending you need to create it exactly as you do for the first time, then AlarmManager s Cancel () as you like but then you need to make it again to set an alarm to pending

** I hope you know some ways to test ...

may be a better way, but for testing purposes For, I will occasionally set up a global debug flag is changed between the testing and production. Then say it can be 4 hours and 2 minutes, it can be a bit more difficult during the day, but you can change the time, time, hours, minutes or whatever. Once you know that this is triggering at the right time, you can change it back and still test it when the time comes for that day but now you know that it should be done.

No comments:

Post a Comment