I have this method called "createAlarms()" which is on initial app setup, sets an alarm for a specific time. On the running of this alarm, it creates a notification which I am creating using a Broadcast Receiver Class.
public void createAlarms() {
cal = Calendar.getInstance();
cal.add(Calendar.HOUR, alarmintervalint);
calintent = new Intent(this, AlarmBroadcastReceiver.class);
calpendingintent = PendingIntent.getBroadcast(this.getApplicationContext(), 12345, calintent, 0);
am = (AlarmManager)getSystemService(Activity.ALARM_SERVICE);
am.set(AlarmManager.RTC_WAKEUP, alarmintervalint, calpendingintent);
}
I want this alarm to repeat every "alarmintervalint" time period. I could do this by using the "am.setRepeating()" function, but my problem is a bit more complicated then that. After sending a certain amount of alarms (such as 50. will be calculated by the program), I want all the values to change, so that the alarmintervalint will change.
private void showNotification(Context context) {
PendingIntent notifpi = PendingIntent.getActivity(context, 0, new Intent(context, Main.class), 0);
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(context)
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle("Hello!")
.setContentText("Welcome!")
.addAction(R.drawable.ic_launcher, "Open App", notifpi);
mBuilder.setContentIntent(notifpi);
mBuilder.setDefaults(Notification.DEFAULT_SOUND);
mBuilder.setAutoCancel(true);
NotificationManager mNotificationManager =
(NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(1, mBuilder.build());
System.out.println("6");
}
For example, right now, an alarm goes off every 2 hours, and I get a notification every 2 hours. After getting 50 notifications, I want to set the Alarm to go off after 3 hours. And again after 50 notifications, make it 4 hours. (This is just an example, it will be a bit more complicated.
How would I do this? Right now what I think is to have some sort of counter in my broadcastreceiver class, and after the counter reaches 50 (in this example's case), it will call upon the createAlarms() class and change the timings and stuff. Would this work?