I am developing an Android application that should run an alarm five times a day:
- times are not constant every day
- after the alarm goes off, I plan the next alarm.
My problem: the alarm notification works for 1 day, then it stops, and when the device reboots twice, the notification does not work, I'm not right now, if there is another way to do this, any help would be greatly appreciated!
code: I have this function to call the broadcast receiver
public static void Start_Notifying(Context context){ Calendar cal = Calendar.getInstance(); cal.setTimeInMillis(System.currentTimeMillis()); cal.add(Calendar.HOUR_OF_DAY,hour); cal.add(Calendar.MINUTE, min); Intent intent = new Intent(context, OnetimeAlarmReceiver.class); intent.setAction("START_NOTIFYING"); PendingIntent pendingIntent = PendingIntent.getBroadcast(context, notify.REQUEST_CODE, intent,0); AlarmManager alarmManager = (AlarmManager) context.getSystemService(ALARM_SERVICE); alarmManager.set(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis() , pendingIntent); SaveAlarmManager(alarmManager, pendingIntent); }
code oneTimeAlarmReciever
public void onReceive(Context context, Intent intent) { main_menu.con = context; Notification notifyDetails; NotificationManager nm = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE); notifyDetails = new Notification(R.drawable.icon,s1,System.currentTimeMillis()); PendingIntent pendingIntent = PendingIntent.getActivity(context, REQUEST_CODE, new Intent(context, prayertimes.class), 0); notifyDetails.setLatestEventInfo(context,s2+ notify.prayName , s3, pendingIntent); notifyDetails.sound=Uri.parse(PlaySound()); nm.notify(NOTIFICATION_ID, notifyDetails); main_menu.notify_me(); }
Notify_me () code
static void notify_me() { hour =pTime.num1; min =pTime.num2; Start_Notifying(con); }
In manifest file
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"></uses-permission> <receiver class =".OnetimeAlarmReceiver" android:name="OnetimeAlarmReceiver"> <intent-filter> <action android:name="START_NOTIFYING" /> <action android:name="android.intent.action.BOOT_COMPLETED"> </action> <data android:mimeType="audio/ogg" /> </intent-filter> </receiver>