This question already has an answer here:
I'm setting multiple alarms on repeat through alarm manager, they are working fine on the day they got set but not repeating at all. I have updated my code but I can't wait all day to check if the code is even working or not so I have tried adb shell dumpsys alarm command but I don't know how to read the output properly and how to extract the times of alarms being set. I have followed some links to understand the output but none is specifiying how to check the exact time of the alarm being set. here is my output
my main code where i'm setting the alarm
final int _id = (int) System.currentTimeMillis();
AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
// alarmManager.setRepeating(AlarmManager.RTC_WAKEUP,AllTime[i],AlarmManager.INTERVAL_DAY,
// PendingIntent.getBroadcast(this, _id, alertIntent, PendingIntent.FLAG_UPDATE_CURRENT));
alarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP,AllTime[i],AlarmManager.INTERVAL_DAY,
PendingIntent.getBroadcast(this, _id, alertIntent, PendingIntent.FLAG_UPDATE_CURRENT));
and this this the broadcast receiver
public void onReceive(Context context, Intent intent) {
String[] myStrings = intent.getStringArrayExtra("strings");
Log.i("okk", "cathing intent values through break" + Arrays.toString(myStrings));
createNotification(context, "Time is here baby", "this is the notification text", "Alert");
Log.i("okk", "cathing intent values through break" + Arrays.toString(myStrings));
}
public void createNotification(Context context, String msg, String msgText, String msgAlert) {
final int _id = (int) System.currentTimeMillis(); // unique request code
// will open mainActivity on notification click, can change it
// PendingIntent notificationIntent = PendingIntent.getActivity(context, _id, new Intent(context, MainActivity.class), 0); // changed from 0 to _id
PendingIntent notificationIntent = PendingIntent.getActivity(context,0, new Intent(context,MainActivity.class),0);
NotificationCompat.Builder mbuilder = new NotificationCompat.Builder(context)
.setSmallIcon(R.drawable.cast_ic_notification_play)
.setContentTitle(msg)
.setTicker(msgAlert)
.setContentText(msgText);
// now intent we want to fire when noti is clicked
mbuilder.setContentIntent(notificationIntent);
// how person is notified
mbuilder.setDefaults(NotificationCompat.DEFAULT_SOUND);
mbuilder.setAutoCancel(true); // noti dismisble when user swipe it away
NotificationManager notificationManager = (NotificationManager)
context.getSystemService((Context.NOTIFICATION_SERVICE));
// Log.i("okk", "NOTIFIED " + intent.getExtras());
notificationManager.notify(1, mbuilder.build()); // changes from 1 to _id
}
maybe it can help you, I've created an opensource project with a GUI version of the "adb shell dumpsys alarms" command. You can find it here:
https://github.com/Dottorhouse/DumpsysAlarm
Hopefully it will help you figure out what's wrong